chamoso commited on
Commit
55b680f
·
verified ·
1 Parent(s): 91e71af

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +17 -5
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 "Provide inputs", None
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={pk} MW={mw:.0f}Da", img
17
 
18
- iface = gr.Interface(predict, [gr.Textbox(label="SMILES"), gr.Textbox(label="Sequence", lines=2)], [gr.Textbox(), gr.Image(type="pil")], title="DeepPharm", examples=[["CC(=O)Oc1ccccc1C(=O)O", "MLARALLL"]])
19
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
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()