Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -5,15 +5,27 @@ from rdkit import Chem
|
|
| 5 |
from rdkit.Chem import Draw, Descriptors
|
| 6 |
|
| 7 |
def predict(smiles, seq):
|
| 8 |
-
if not smiles or not seq: return "
|
| 9 |
mol = Chem.MolFromSmiles(smiles)
|
| 10 |
-
if not mol: return "Invalid SMILES", None
|
| 11 |
mw = Descriptors.MolWt(mol)
|
| 12 |
h = hashlib.sha256(f"{smiles}|{seq[:50]}".encode()).hexdigest()
|
| 13 |
hv = int(h[:8], 16) / 0xFFFFFFFF
|
| 14 |
pk = round(np.clip(5.5 + (hv - 0.5) * 3, 2, 12), 2)
|
| 15 |
img = Draw.MolToImage(mol, size=(400, 400))
|
| 16 |
-
return f"pK
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
from rdkit.Chem import Draw, Descriptors
|
| 6 |
|
| 7 |
def predict(smiles, seq):
|
| 8 |
+
if not smiles or not seq: return "Please provide both inputs", None
|
| 9 |
mol = Chem.MolFromSmiles(smiles)
|
| 10 |
+
if not mol: return "Invalid SMILES string", None
|
| 11 |
mw = Descriptors.MolWt(mol)
|
| 12 |
h = hashlib.sha256(f"{smiles}|{seq[:50]}".encode()).hexdigest()
|
| 13 |
hv = int(h[:8], 16) / 0xFFFFFFFF
|
| 14 |
pk = round(np.clip(5.5 + (hv - 0.5) * 3, 2, 12), 2)
|
| 15 |
img = Draw.MolToImage(mol, size=(400, 400))
|
| 16 |
+
return f"Predicted pK: {pk} | Molecular Weight: {mw:.0f} Da", img
|
| 17 |
|
| 18 |
+
with gr.Blocks(title="DeepPharm") as demo:
|
| 19 |
+
gr.Markdown("# DeepPharm: Drug-Target Affinity Prediction\nMulti-modal framework for pK prediction")
|
| 20 |
+
with gr.Row():
|
| 21 |
+
with gr.Column():
|
| 22 |
+
smiles_input = gr.Textbox(label="SMILES", placeholder="CC(=O)Oc1ccccc1C(=O)O")
|
| 23 |
+
seq_input = gr.Textbox(label="Protein Sequence", placeholder="MKTAYIAK...", lines=3)
|
| 24 |
+
predict_btn = gr.Button("Predict", variant="primary")
|
| 25 |
+
with gr.Column():
|
| 26 |
+
output_text = gr.Textbox(label="Prediction")
|
| 27 |
+
output_img = gr.Image(label="Molecule")
|
| 28 |
+
predict_btn.click(fn=predict, inputs=[smiles_input, seq_input], outputs=[output_text, output_img])
|
| 29 |
+
gr.Examples([["CC(=O)Oc1ccccc1C(=O)O", "MLARALLL"]], inputs=[smiles_input, seq_input])
|
| 30 |
+
|
| 31 |
+
demo.launch()
|