Update app.py
Browse files
app.py
CHANGED
@@ -33,7 +33,11 @@ def drug_discovery(disease, symptoms):
|
|
33 |
|
34 |
# Convert binary to base64
|
35 |
img_base64 = base64.b64encode(img_data).decode("utf-8")
|
36 |
-
img_html = f'<
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# 3D molecule
|
39 |
mol3d = Chem.AddHs(mol)
|
@@ -41,36 +45,69 @@ def drug_discovery(disease, symptoms):
|
|
41 |
AllChem.UFFOptimizeMolecule(mol3d)
|
42 |
mb = Chem.MolToMolBlock(mol3d)
|
43 |
|
44 |
-
viewer = py3Dmol.view(width=
|
45 |
viewer.addModel(mb, "mol")
|
46 |
-
viewer.setStyle({"stick": {}})
|
47 |
viewer.setBackgroundColor("white")
|
48 |
viewer.zoomTo()
|
|
|
|
|
49 |
viewer_html_raw = viewer._make_html()
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
56 |
|
57 |
return literature, smiles, img_html, viewer_html
|
58 |
|
59 |
# Gradio UI
|
60 |
-
disease_input = gr.Textbox(label="Enter Disease", value="lung cancer")
|
61 |
-
symptom_input = gr.Textbox(label="Enter Symptoms", value="shortness of breath, weight loss")
|
62 |
-
lit_output = gr.Textbox(label="Literature Insights")
|
63 |
-
smiles_output = gr.Textbox(label="SMILES
|
64 |
-
img_output = gr.HTML(label="2D
|
65 |
-
viewer_output = gr.HTML(label="3D Molecule
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
iface = gr.Interface(
|
68 |
fn=drug_discovery,
|
69 |
inputs=[disease_input, symptom_input],
|
70 |
outputs=[lit_output, smiles_output, img_output, viewer_output],
|
71 |
-
title="
|
72 |
-
description="
|
|
|
|
|
73 |
)
|
74 |
|
75 |
iface.launch(share=True)
|
76 |
|
|
|
|
33 |
|
34 |
# Convert binary to base64
|
35 |
img_base64 = base64.b64encode(img_data).decode("utf-8")
|
36 |
+
img_html = f'''<div style="text-align:center; margin-top: 10px; animation: fadeIn 2s ease-in-out;">
|
37 |
+
<img src="data:image/png;base64,{img_base64}" alt="2D Molecule"
|
38 |
+
style="border-radius: 16px; box-shadow: 0 6px 20px rgba(0,128,128,0.2); border: 1px solid #ccc;">
|
39 |
+
<div style='font-family: Arial, sans-serif; color: #2c3e50; margin-top: 8px; animation: slideUp 1.5s ease-in-out;'>💊 Visualized Drug Molecule (2D)</div>
|
40 |
+
</div>'''
|
41 |
|
42 |
# 3D molecule
|
43 |
mol3d = Chem.AddHs(mol)
|
|
|
45 |
AllChem.UFFOptimizeMolecule(mol3d)
|
46 |
mb = Chem.MolToMolBlock(mol3d)
|
47 |
|
48 |
+
viewer = py3Dmol.view(width=420, height=420)
|
49 |
viewer.addModel(mb, "mol")
|
50 |
+
viewer.setStyle({"stick": {"colorscheme": "tealCarbon"}})
|
51 |
viewer.setBackgroundColor("white")
|
52 |
viewer.zoomTo()
|
53 |
+
viewer.rotate(1)
|
54 |
+
viewer.spin(True)
|
55 |
viewer_html_raw = viewer._make_html()
|
56 |
|
57 |
+
viewer_html = f'''
|
58 |
+
<div style="text-align:center; margin-top: 20px; animation: zoomIn 2s ease-in-out;">
|
59 |
+
<iframe srcdoc="{viewer_html_raw.replace('"', '"')}"
|
60 |
+
width="440" height="440" frameborder="0"
|
61 |
+
style="border-radius: 16px; box-shadow: 0 8px 30px rgba(0,128,128,0.25);"></iframe>
|
62 |
+
<div style='font-family: Arial, sans-serif; color: #2c3e50; margin-top: 8px; animation: slideUp 1.5s ease-in-out;'>🧬 Animated 3D Molecule (Stick View)</div>
|
63 |
+
</div>'''
|
64 |
|
65 |
return literature, smiles, img_html, viewer_html
|
66 |
|
67 |
# Gradio UI
|
68 |
+
disease_input = gr.Textbox(label="🏥 Enter Disease (e.g., lung cancer)", value="lung cancer")
|
69 |
+
symptom_input = gr.Textbox(label="💉 Enter Symptoms (e.g., cough, weight loss)", value="shortness of breath, weight loss")
|
70 |
+
lit_output = gr.Textbox(label="📰 Literature Insights from BioGPT")
|
71 |
+
smiles_output = gr.Textbox(label="🧪 SMILES Representation")
|
72 |
+
img_output = gr.HTML(label="🖼️ Molecule 2D Visualization")
|
73 |
+
viewer_output = gr.HTML(label="🔬 3D Drug Molecule Animation")
|
74 |
+
|
75 |
+
custom_css = """
|
76 |
+
@keyframes fadeIn {
|
77 |
+
from {opacity: 0;}
|
78 |
+
to {opacity: 1;}
|
79 |
+
}
|
80 |
+
|
81 |
+
@keyframes slideUp {
|
82 |
+
from {transform: translateY(40px); opacity: 0;}
|
83 |
+
to {transform: translateY(0); opacity: 1;}
|
84 |
+
}
|
85 |
+
|
86 |
+
@keyframes zoomIn {
|
87 |
+
from {transform: scale(0.5); opacity: 0;}
|
88 |
+
to {transform: scale(1); opacity: 1;}
|
89 |
+
}
|
90 |
+
|
91 |
+
body {
|
92 |
+
background: linear-gradient(to right, #e0f7fa, #ffffff);
|
93 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
94 |
+
}
|
95 |
+
|
96 |
+
.gradio-container {
|
97 |
+
animation: fadeIn 1.5s ease-in-out;
|
98 |
+
}
|
99 |
+
"""
|
100 |
|
101 |
iface = gr.Interface(
|
102 |
fn=drug_discovery,
|
103 |
inputs=[disease_input, symptom_input],
|
104 |
outputs=[lit_output, smiles_output, img_output, viewer_output],
|
105 |
+
title="🏥 AI-Powered Drug Discovery for Hospitals",
|
106 |
+
description="This hospital-themed platform takes a disease and symptoms as input, retrieves biomedical insights using BioGPT, and visualizes potential drug molecules in 2D and animated 3D. Ideal for clinical research and pharma innovation.",
|
107 |
+
theme="default",
|
108 |
+
css=custom_css
|
109 |
)
|
110 |
|
111 |
iface.launch(share=True)
|
112 |
|
113 |
+
|