Update app.py
Browse files
app.py
CHANGED
|
@@ -108,69 +108,78 @@ def render_ui():
|
|
| 108 |
with st.spinner("Thinking... Gathering and analyzing data across 5 systems..."):
|
| 109 |
results = asyncio.run(orchestrate_search(query))
|
| 110 |
st.success("Search complete! π")
|
| 111 |
-
save_query(query, results) # Save to workspace
|
| 112 |
|
| 113 |
if results:
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
# Follow-up AI Q&A
|
| 176 |
st.markdown("---")
|
|
|
|
| 108 |
with st.spinner("Thinking... Gathering and analyzing data across 5 systems..."):
|
| 109 |
results = asyncio.run(orchestrate_search(query))
|
| 110 |
st.success("Search complete! π")
|
|
|
|
| 111 |
|
| 112 |
if results:
|
| 113 |
+
tabs = st.tabs(["π Results", "πΊοΈ Knowledge Graph", "π Visualizations"])
|
| 114 |
+
|
| 115 |
+
# --- TAB 1: Results ---
|
| 116 |
+
with tabs[0]:
|
| 117 |
+
for i, paper in enumerate(results["papers"], 1):
|
| 118 |
+
st.markdown(f"**{i}. [{paper['title']}]({paper['link']})** \n*{paper['authors']}* ({paper['source']})")
|
| 119 |
+
st.markdown(f"<div style='font-size: 0.9em; color: gray'>{paper['summary']}</div>", unsafe_allow_html=True)
|
| 120 |
+
|
| 121 |
+
# Save to workspace (user-initiated, for clarity)
|
| 122 |
+
if st.button("Save this search to Workspace"):
|
| 123 |
+
save_query(query, results)
|
| 124 |
+
st.success("Saved to your workspace!")
|
| 125 |
+
|
| 126 |
+
# Export as CSV
|
| 127 |
+
if results["papers"]:
|
| 128 |
+
df = pd.DataFrame(results["papers"])
|
| 129 |
+
csv = df.to_csv(index=False)
|
| 130 |
+
st.download_button(
|
| 131 |
+
label="π₯ Download results as CSV",
|
| 132 |
+
data=csv,
|
| 133 |
+
file_name="medgenesis_results.csv",
|
| 134 |
+
mime="text/csv",
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
# Export as PDF
|
| 138 |
+
if results["papers"]:
|
| 139 |
+
pdf_bytes = generate_pdf(results["papers"])
|
| 140 |
+
st.download_button(
|
| 141 |
+
label="π Download results as PDF",
|
| 142 |
+
data=pdf_bytes,
|
| 143 |
+
file_name="medgenesis_results.pdf",
|
| 144 |
+
mime="application/pdf",
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
# UMLS Concepts
|
| 148 |
+
st.markdown("### π§ Biomedical Concept Enrichment (UMLS)")
|
| 149 |
+
for concept in results["umls"]:
|
| 150 |
+
if concept["cui"]:
|
| 151 |
+
st.markdown(f"πΉ **{concept['name']}** (CUI: `{concept['cui']}`): {concept['definition'] or 'No definition available'}")
|
| 152 |
+
|
| 153 |
+
# Drug Safety
|
| 154 |
+
st.markdown("### π Drug Safety Insights (OpenFDA)")
|
| 155 |
+
for drug_report in results["drug_safety"]:
|
| 156 |
+
if drug_report:
|
| 157 |
+
st.json(drug_report)
|
| 158 |
+
|
| 159 |
+
# AI Summary
|
| 160 |
+
st.markdown("### π€ AI-Powered Summary")
|
| 161 |
+
st.info(results["ai_summary"])
|
| 162 |
+
|
| 163 |
+
# Suggested Reading
|
| 164 |
+
st.markdown("### π Suggested Links")
|
| 165 |
+
for link in results["suggested_reading"]:
|
| 166 |
+
st.write(f"- {link}")
|
| 167 |
+
|
| 168 |
+
# --- TAB 2: Knowledge Graph ---
|
| 169 |
+
with tabs[1]:
|
| 170 |
+
st.markdown("#### Explore Connections")
|
| 171 |
+
kg_html_path = build_knowledge_graph(results["papers"], results["umls"], results["drug_safety"])
|
| 172 |
+
with open(kg_html_path, 'r', encoding='utf-8') as f:
|
| 173 |
+
kg_html = f.read()
|
| 174 |
+
components.html(kg_html, height=600)
|
| 175 |
+
|
| 176 |
+
# --- TAB 3: Visualizations ---
|
| 177 |
+
with tabs[2]:
|
| 178 |
+
pub_years = [p["published"] for p in results["papers"] if p.get("published")]
|
| 179 |
+
if pub_years:
|
| 180 |
+
fig = px.histogram(pub_years, nbins=10, title="Publication Year Distribution")
|
| 181 |
+
st.plotly_chart(fig)
|
| 182 |
+
# Placeholder for more charts
|
| 183 |
|
| 184 |
# Follow-up AI Q&A
|
| 185 |
st.markdown("---")
|