Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,13 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
|
| 3 |
-
from agents import run_pipeline
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
# ====================================
|
| 7 |
-
# 3D MOLECULE VIEWER
|
| 8 |
-
# ====================================
|
| 9 |
-
|
| 10 |
def create_molecule_viewer(smiles):
|
| 11 |
|
| 12 |
-
|
| 13 |
<iframe
|
| 14 |
width="100%"
|
| 15 |
-
height="
|
| 16 |
frameborder="0"
|
| 17 |
|
| 18 |
srcdoc='
|
|
|
|
| 19 |
<html>
|
| 20 |
|
| 21 |
<head>
|
|
@@ -24,7 +16,7 @@ def create_molecule_viewer(smiles):
|
|
| 24 |
|
| 25 |
</head>
|
| 26 |
|
| 27 |
-
<body style="margin:0
|
| 28 |
|
| 29 |
<div
|
| 30 |
id="viewer"
|
|
@@ -38,16 +30,12 @@ def create_molecule_viewer(smiles):
|
|
| 38 |
|
| 39 |
<script>
|
| 40 |
|
| 41 |
-
let
|
| 42 |
-
document.getElementById("viewer")
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
{{
|
| 48 |
-
backgroundColor: "white"
|
| 49 |
-
}}
|
| 50 |
-
);
|
| 51 |
|
| 52 |
viewer.addModel(
|
| 53 |
"{smiles}",
|
|
@@ -59,7 +47,7 @@ def create_molecule_viewer(smiles):
|
|
| 59 |
{{
|
| 60 |
stick: {{}},
|
| 61 |
sphere: {{
|
| 62 |
-
scale:
|
| 63 |
}}
|
| 64 |
}}
|
| 65 |
);
|
|
@@ -75,162 +63,7 @@ def create_molecule_viewer(smiles):
|
|
| 75 |
</body>
|
| 76 |
|
| 77 |
</html>
|
|
|
|
| 78 |
'>
|
| 79 |
</iframe>
|
| 80 |
-
"""
|
| 81 |
-
|
| 82 |
-
return iframe
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
# ====================================
|
| 86 |
-
# MAIN ANALYSIS
|
| 87 |
-
# ====================================
|
| 88 |
-
|
| 89 |
-
def analyze(symptoms, followup, audio):
|
| 90 |
-
|
| 91 |
-
try:
|
| 92 |
-
|
| 93 |
-
combined_input = symptoms
|
| 94 |
-
|
| 95 |
-
if followup and followup.strip():
|
| 96 |
-
|
| 97 |
-
combined_input += (
|
| 98 |
-
" " + followup
|
| 99 |
-
)
|
| 100 |
-
|
| 101 |
-
result = run_pipeline(
|
| 102 |
-
combined_input,
|
| 103 |
-
audio
|
| 104 |
-
)
|
| 105 |
-
|
| 106 |
-
response = result["response"]
|
| 107 |
-
|
| 108 |
-
pubmed = "\n".join(
|
| 109 |
-
result["pubmed"]
|
| 110 |
-
)
|
| 111 |
-
|
| 112 |
-
molecule_info = ""
|
| 113 |
-
|
| 114 |
-
molecule_html = ""
|
| 115 |
-
|
| 116 |
-
if result["molecules"]:
|
| 117 |
-
|
| 118 |
-
molecule = result["molecules"][0]
|
| 119 |
-
|
| 120 |
-
molecule_info = f"""
|
| 121 |
-
Drug: {molecule['name']}
|
| 122 |
-
|
| 123 |
-
SMILES:
|
| 124 |
-
{molecule['smiles']}
|
| 125 |
-
|
| 126 |
-
Molecular Weight:
|
| 127 |
-
{molecule['molecular_weight']}
|
| 128 |
-
"""
|
| 129 |
-
|
| 130 |
-
molecule_html = create_molecule_viewer(
|
| 131 |
-
molecule["smiles"]
|
| 132 |
-
)
|
| 133 |
-
|
| 134 |
-
return (
|
| 135 |
-
response,
|
| 136 |
-
pubmed,
|
| 137 |
-
molecule_info,
|
| 138 |
-
molecule_html
|
| 139 |
-
)
|
| 140 |
-
|
| 141 |
-
except Exception as e:
|
| 142 |
-
|
| 143 |
-
return (
|
| 144 |
-
f"Error: {str(e)}",
|
| 145 |
-
"",
|
| 146 |
-
"",
|
| 147 |
-
""
|
| 148 |
-
)
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
# ====================================
|
| 152 |
-
# UI
|
| 153 |
-
# ====================================
|
| 154 |
-
|
| 155 |
-
custom_css = """
|
| 156 |
-
|
| 157 |
-
body {
|
| 158 |
-
|
| 159 |
-
background:
|
| 160 |
-
linear-gradient(
|
| 161 |
-
to right,
|
| 162 |
-
#141e30,
|
| 163 |
-
#243b55
|
| 164 |
-
);
|
| 165 |
-
|
| 166 |
-
color:white;
|
| 167 |
-
}
|
| 168 |
-
|
| 169 |
-
"""
|
| 170 |
-
|
| 171 |
-
with gr.Blocks(
|
| 172 |
-
theme=gr.themes.Soft(),
|
| 173 |
-
css=custom_css
|
| 174 |
-
) as demo:
|
| 175 |
-
|
| 176 |
-
gr.Markdown(
|
| 177 |
-
"""
|
| 178 |
-
# 💊 AI Biomedical Assistant
|
| 179 |
-
|
| 180 |
-
Real-Time Biomedical Intelligence System
|
| 181 |
-
"""
|
| 182 |
-
)
|
| 183 |
-
|
| 184 |
-
symptoms_input = gr.Textbox(
|
| 185 |
-
label="🩺 Symptoms",
|
| 186 |
-
placeholder="Example: nausea, chest pain..."
|
| 187 |
-
)
|
| 188 |
-
|
| 189 |
-
followup_input = gr.Textbox(
|
| 190 |
-
label="💬 Follow-Up Information"
|
| 191 |
-
)
|
| 192 |
-
|
| 193 |
-
audio_input = gr.Audio(
|
| 194 |
-
sources=["microphone"],
|
| 195 |
-
type="filepath",
|
| 196 |
-
label="🎙️ Record Symptoms"
|
| 197 |
-
)
|
| 198 |
-
|
| 199 |
-
analyze_btn = gr.Button(
|
| 200 |
-
"🧠 Analyze"
|
| 201 |
-
)
|
| 202 |
-
|
| 203 |
-
diagnosis_output = gr.Markdown(
|
| 204 |
-
label="🧠 Biomedical Report"
|
| 205 |
-
)
|
| 206 |
-
|
| 207 |
-
pubmed_output = gr.Textbox(
|
| 208 |
-
label="📄 PubMed IDs",
|
| 209 |
-
lines=5
|
| 210 |
-
)
|
| 211 |
-
|
| 212 |
-
molecule_output = gr.Textbox(
|
| 213 |
-
label="🧪 Drug Information",
|
| 214 |
-
lines=8
|
| 215 |
-
)
|
| 216 |
-
|
| 217 |
-
molecule_viewer = gr.HTML(
|
| 218 |
-
label="🧬 Animated 3D Molecule"
|
| 219 |
-
)
|
| 220 |
-
|
| 221 |
-
analyze_btn.click(
|
| 222 |
-
fn=analyze,
|
| 223 |
-
inputs=[
|
| 224 |
-
symptoms_input,
|
| 225 |
-
followup_input,
|
| 226 |
-
audio_input
|
| 227 |
-
],
|
| 228 |
-
outputs=[
|
| 229 |
-
diagnosis_output,
|
| 230 |
-
pubmed_output,
|
| 231 |
-
molecule_output,
|
| 232 |
-
molecule_viewer
|
| 233 |
-
]
|
| 234 |
-
)
|
| 235 |
-
|
| 236 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
def create_molecule_viewer(smiles):
|
| 2 |
|
| 3 |
+
return f"""
|
| 4 |
<iframe
|
| 5 |
width="100%"
|
| 6 |
+
height="500"
|
| 7 |
frameborder="0"
|
| 8 |
|
| 9 |
srcdoc='
|
| 10 |
+
|
| 11 |
<html>
|
| 12 |
|
| 13 |
<head>
|
|
|
|
| 16 |
|
| 17 |
</head>
|
| 18 |
|
| 19 |
+
<body style="margin:0">
|
| 20 |
|
| 21 |
<div
|
| 22 |
id="viewer"
|
|
|
|
| 30 |
|
| 31 |
<script>
|
| 32 |
|
| 33 |
+
let viewer = $3Dmol.createViewer(
|
| 34 |
+
document.getElementById("viewer"),
|
| 35 |
+
{{
|
| 36 |
+
backgroundColor: "white"
|
| 37 |
+
}}
|
| 38 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
viewer.addModel(
|
| 41 |
"{smiles}",
|
|
|
|
| 47 |
{{
|
| 48 |
stick: {{}},
|
| 49 |
sphere: {{
|
| 50 |
+
scale:0.3
|
| 51 |
}}
|
| 52 |
}}
|
| 53 |
);
|
|
|
|
| 63 |
</body>
|
| 64 |
|
| 65 |
</html>
|
| 66 |
+
|
| 67 |
'>
|
| 68 |
</iframe>
|
| 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