Update app.py
Browse files
app.py
CHANGED
@@ -1,86 +1,66 @@
|
|
1 |
-
import
|
2 |
from transformers import pipeline
|
3 |
from rdkit import Chem
|
4 |
-
from rdkit.Chem import AllChem
|
5 |
-
from rdkit.Chem import
|
|
|
6 |
import base64
|
7 |
from io import BytesIO
|
|
|
8 |
|
9 |
-
|
10 |
-
bio_gpt = pipeline("text-generation", model="microsoft/BioGPT-Large")
|
11 |
-
chemberta = pipeline("text-classification", model="seyonec/ChemBERTa-zinc-base-chemprop")
|
12 |
-
fda_gpt = pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")
|
13 |
|
14 |
-
|
15 |
-
mol = Chem.MolFromSmiles(smiles)
|
16 |
-
mol = Chem.AddHs(mol)
|
17 |
-
AllChem.EmbedMolecule(mol, AllChem.ETKDG())
|
18 |
-
AllChem.UFFOptimizeMolecule(mol)
|
19 |
-
drawer = Draw.MolDraw2DSVG(300, 300)
|
20 |
-
drawer.DrawMolecule(mol)
|
21 |
-
drawer.FinishDrawing()
|
22 |
-
return drawer.GetDrawingText()
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
AllChem.UFFOptimizeMolecule(mol)
|
30 |
-
mol_block = Chem.MolToMolBlock(mol)
|
31 |
-
mol_block = mol_block.replace("\n", "\\n")
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
viewer.addModel(molBlock, "mol");
|
40 |
-
viewer.setStyle({{}}, {{stick:{{}}}});
|
41 |
-
viewer.zoomTo();
|
42 |
-
viewer.animate({{loop: "backAndForth"}});
|
43 |
-
viewer.render();
|
44 |
-
</script>
|
45 |
-
"""
|
46 |
-
return html
|
47 |
-
except Exception as e:
|
48 |
-
return f"<p>Error rendering 3D molecule: {str(e)}</p>"
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
literature = bio_gpt(prompt, max_length=250)[0]['generated_text']
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
|
|
|
|
|
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
gr.Textbox(label="π§Ύ Symptoms", placeholder="e.g. shortness of breath, weight loss")
|
67 |
-
]
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
|
78 |
-
|
79 |
-
fn=drug_discovery,
|
80 |
-
inputs=inputs,
|
81 |
-
outputs=outputs,
|
82 |
-
title="π AI-Driven Drug Discovery using LLMs",
|
83 |
-
description="Enter a disease and its symptoms. This app generates literature insights, a possible molecule in SMILES format, scores its drug-likeness, and shows 2D & 3D views."
|
84 |
-
)
|
85 |
|
86 |
-
|
|
|
|
1 |
+
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from rdkit import Chem
|
4 |
+
from rdkit.Chem import AllChem
|
5 |
+
from rdkit.Chem.Draw import rdMolDraw2D
|
6 |
+
from rdkit.Chem import rdDepictor
|
7 |
import base64
|
8 |
from io import BytesIO
|
9 |
+
import py3Dmol
|
10 |
|
11 |
+
st.set_page_config(page_title="Drug Discovery using LLMs", layout="wide")
|
|
|
|
|
|
|
12 |
|
13 |
+
st.title("𧬠Drug Discovery using LLMs")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
with st.sidebar:
|
16 |
+
st.header("π¦ Disease")
|
17 |
+
disease = st.text_input("Enter disease", "lung cancer")
|
18 |
+
st.header("π§Ύ Symptoms")
|
19 |
+
symptoms = st.text_input("Enter symptoms", "shortness of breath, weight loss")
|
|
|
|
|
|
|
20 |
|
21 |
+
if st.button("Submit"):
|
22 |
+
with st.spinner("π Discovering insights and potential drugs..."):
|
23 |
+
# BioGPT pipeline
|
24 |
+
bio_gpt = pipeline("text-generation", model="microsoft/BioGPT-Large")
|
25 |
+
prompt = f"Recent treatments for {disease} with symptoms: {symptoms}."
|
26 |
+
literature = bio_gpt(prompt, max_length=200)[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
st.subheader("π Literature Insights")
|
29 |
+
st.write(literature)
|
|
|
30 |
|
31 |
+
# Generate a dummy SMILES for demo (could replace with MoLeR/Diffusion)
|
32 |
+
st.subheader("π§ͺ SMILES String")
|
33 |
+
smiles = "CC(C)CC" # Isopentane (dummy drug structure)
|
34 |
+
st.write(f"SMILES: {smiles}")
|
35 |
|
36 |
+
# Draw 2D molecule (optional, not shown if 3D works)
|
37 |
+
mol = Chem.MolFromSmiles(smiles)
|
38 |
+
AllChem.Compute2DCoords(mol)
|
39 |
+
rdDepictor.Compute2DCoords(mol)
|
40 |
+
drawer = rdMolDraw2D.MolDraw2DCairo(300, 300)
|
41 |
+
drawer.DrawMolecule(mol)
|
42 |
+
drawer.FinishDrawing()
|
43 |
+
img_data = drawer.GetDrawingText()
|
44 |
+
st.image(img_data, caption="2D Structure", use_column_width=False)
|
45 |
|
46 |
+
# Generate 3D coordinates
|
47 |
+
mol3d = Chem.AddHs(mol)
|
48 |
+
AllChem.EmbedMolecule(mol3d)
|
49 |
+
AllChem.UFFOptimizeMolecule(mol3d)
|
50 |
|
51 |
+
# Extract 3D coordinates for py3Dmol
|
52 |
+
mb = Chem.MolToMolBlock(mol3d)
|
|
|
|
|
53 |
|
54 |
+
st.subheader("π¬ 3D Structure Viewer")
|
55 |
+
xyzview = py3Dmol.view(width=400, height=400)
|
56 |
+
xyzview.addModel(mb, "mol")
|
57 |
+
xyzview.setStyle({"stick": {}})
|
58 |
+
xyzview.setBackgroundColor("white")
|
59 |
+
xyzview.zoomTo()
|
60 |
+
xyzview.show()
|
61 |
+
st.components.v1.html(xyzview._make_html(), height=400)
|
62 |
|
63 |
+
st.success("β
Done")
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
else:
|
66 |
+
st.info("π Enter disease and symptoms, then hit Submit to discover a molecule.")
|