mgbam commited on
Commit
c1cd51c
Β·
verified Β·
1 Parent(s): 18f24dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -61
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
- # Papers
115
- st.markdown("### πŸ“š Most Relevant Papers")
116
- for i, paper in enumerate(results["papers"], 1):
117
- st.markdown(f"**{i}. [{paper['title']}]({paper['link']})** \n*{paper['authors']}* ({paper['source']})")
118
- st.markdown(f"<div style='font-size: 0.9em; color: gray'>{paper['summary']}</div>", unsafe_allow_html=True)
119
-
120
- # --- INTERACTIVE VISUALIZATION: Publication Year Histogram ---
121
- pub_years = [p["published"] for p in results["papers"] if p.get("published")]
122
- if pub_years:
123
- fig = px.histogram(pub_years, nbins=10, title="Publication Year Distribution")
124
- st.plotly_chart(fig)
125
-
126
- # --- INTERACTIVE KNOWLEDGE GRAPH ---
127
- st.markdown("### πŸ—ΊοΈ Knowledge Graph Explorer")
128
- kg_html_path = build_knowledge_graph(results["papers"], results["umls"], results["drug_safety"])
129
- with open(kg_html_path, 'r', encoding='utf-8') as f:
130
- kg_html = f.read()
131
- components.html(kg_html, height=600)
132
-
133
- # Export as CSV
134
- if results["papers"]:
135
- df = pd.DataFrame(results["papers"])
136
- csv = df.to_csv(index=False)
137
- st.download_button(
138
- label="πŸ“₯ Download results as CSV",
139
- data=csv,
140
- file_name="medgenesis_results.csv",
141
- mime="text/csv",
142
- )
143
-
144
- # Export as PDF
145
- if results["papers"]:
146
- pdf_bytes = generate_pdf(results["papers"])
147
- st.download_button(
148
- label="πŸ“„ Download results as PDF",
149
- data=pdf_bytes,
150
- file_name="medgenesis_results.pdf",
151
- mime="application/pdf",
152
- )
153
-
154
- # UMLS Concepts
155
- st.markdown("### 🧠 Biomedical Concept Enrichment (UMLS)")
156
- for concept in results["umls"]:
157
- if concept["cui"]:
158
- st.markdown(f"πŸ”Ή **{concept['name']}** (CUI: `{concept['cui']}`): {concept['definition'] or 'No definition available'}")
159
-
160
- # Drug Safety
161
- st.markdown("### πŸ’Š Drug Safety Insights (OpenFDA)")
162
- for drug_report in results["drug_safety"]:
163
- if drug_report:
164
- st.json(drug_report)
165
-
166
- # AI Summary
167
- st.markdown("### πŸ€– AI-Powered Summary")
168
- st.info(results["ai_summary"])
169
-
170
- # Suggested Reading
171
- st.markdown("### πŸ“– Suggested Links")
172
- for link in results["suggested_reading"]:
173
- st.write(f"- {link}")
 
 
 
 
 
 
 
 
 
 
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("---")