mgbam commited on
Commit
64163be
Β·
verified Β·
1 Parent(s): c17cf5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -30,7 +30,7 @@ from mcp.alerts import check_alerts
30
  # Streamlit telemetry directory β†’ /tmp
31
  os.environ.update({
32
  "STREAMLIT_DATA_DIR": "/tmp/.streamlit",
33
- "XDG_STATE_HOME" : "/tmp",
34
  "STREAMLIT_BROWSER_GATHERUSAGESTATS": "false",
35
  })
36
  pathlib.Path("/tmp/.streamlit").mkdir(parents=True, exist_ok=True)
@@ -55,7 +55,6 @@ def _pdf(papers: list[dict]) -> bytes:
55
  pdf.set_font("Helvetica", "B", 11)
56
  pdf.multi_cell(0, 7, _latin1_safe(f"{i}. {p.get('title','')}"))
57
  pdf.set_font("Helvetica", "", 9)
58
- # fixed string literal with explicit newlines
59
  body = (
60
  f"{p.get('authors','')}\n"
61
  f"{p.get('summary','')}\n"
@@ -105,7 +104,7 @@ def render_ui():
105
 
106
  # Controls
107
  engine = st.radio("LLM engine", ["openai", "gemini"], horizontal=True)
108
- query = st.text_input("Enter biomedical question", placeholder="e.g. CRISPR glioblastoma therapy")
109
 
110
  # Alerts
111
  if get_workspace():
@@ -140,7 +139,7 @@ def render_ui():
140
  # Tabs
141
  tabs = st.tabs(["Results", "Genes", "Trials", "Variants", "Graph", "Metrics", "Visuals"])
142
 
143
- # --- Results tab
144
  with tabs[0]:
145
  st.subheader("Literature")
146
  for i, p in enumerate(res['papers'], 1):
@@ -167,7 +166,7 @@ def render_ui():
167
  st.subheader("AI summary")
168
  st.info(res['ai_summary'])
169
 
170
- # --- Genes tab
171
  with tabs[1]:
172
  st.header("Gene / Variant signals")
173
  valid_genes = [g for g in res['genes'] if isinstance(g, dict)]
@@ -189,9 +188,11 @@ def render_ui():
189
  st.markdown("### DisGeNET links")
190
  st.json(gene_disease[:15])
191
 
192
- # --- Trials tab
193
  with tabs[2]:
194
  st.header("Clinical trials")
 
 
195
  trials = res['clinical_trials']
196
  if not trials:
197
  st.info("No trials returned (rate-limited or none found).")
@@ -202,21 +203,23 @@ def render_ui():
202
  f"Phase {t.get('phase','?')} | Status {t.get('status','?')}"
203
  )
204
 
205
- # --- Variants tab
206
  with tabs[3]:
207
  st.header("Cancer variants (cBioPortal)")
 
 
208
  variants = res['variants']
209
  if not variants:
210
  st.info("No variants for this gene/profile.")
211
  else:
212
  st.json(variants[:30])
213
 
214
- # --- Graph tab
215
  with tabs[4]:
216
  nodes, edges, cfg = build_agraph(res['papers'], res['umls'], res['drug_safety'])
217
  agraph(nodes, edges, cfg)
218
 
219
- # --- Metrics tab
220
  with tabs[5]:
221
  G = build_nx([n.__dict__ for n in nodes], [e.__dict__ for e in edges])
222
  st.metric("Density", f"{get_density(G):.3f}")
@@ -225,13 +228,13 @@ def render_ui():
225
  lab = next((n.label for n in nodes if n.id == nid), nid)
226
  st.write(f"- {lab} {sc:.3f}")
227
 
228
- # --- Visuals tab
229
  with tabs[6]:
230
  years = [p.get('published') for p in res['papers'] if p.get('published')]
231
  if years:
232
  st.plotly_chart(px.histogram(years, nbins=12, title="Publication Year"))
233
 
234
- # Follow-up QA (outside any tab)
235
  st.markdown("---")
236
  input_col, button_col = st.columns([4, 1])
237
  with input_col:
 
30
  # Streamlit telemetry directory β†’ /tmp
31
  os.environ.update({
32
  "STREAMLIT_DATA_DIR": "/tmp/.streamlit",
33
+ "XDG_STATE_HOME": "/tmp",
34
  "STREAMLIT_BROWSER_GATHERUSAGESTATS": "false",
35
  })
36
  pathlib.Path("/tmp/.streamlit").mkdir(parents=True, exist_ok=True)
 
55
  pdf.set_font("Helvetica", "B", 11)
56
  pdf.multi_cell(0, 7, _latin1_safe(f"{i}. {p.get('title','')}"))
57
  pdf.set_font("Helvetica", "", 9)
 
58
  body = (
59
  f"{p.get('authors','')}\n"
60
  f"{p.get('summary','')}\n"
 
104
 
105
  # Controls
106
  engine = st.radio("LLM engine", ["openai", "gemini"], horizontal=True)
107
+ query = st.text_input("Enter biomedical question", placeholder="e.g. CRISPR glioblastoma therapy")
108
 
109
  # Alerts
110
  if get_workspace():
 
139
  # Tabs
140
  tabs = st.tabs(["Results", "Genes", "Trials", "Variants", "Graph", "Metrics", "Visuals"])
141
 
142
+ # --- Results tab ---
143
  with tabs[0]:
144
  st.subheader("Literature")
145
  for i, p in enumerate(res['papers'], 1):
 
166
  st.subheader("AI summary")
167
  st.info(res['ai_summary'])
168
 
169
+ # --- Genes tab ---
170
  with tabs[1]:
171
  st.header("Gene / Variant signals")
172
  valid_genes = [g for g in res['genes'] if isinstance(g, dict)]
 
188
  st.markdown("### DisGeNET links")
189
  st.json(gene_disease[:15])
190
 
191
+ # --- Trials tab ---
192
  with tabs[2]:
193
  st.header("Clinical trials")
194
+ # Debug: show raw response
195
+ st.write("πŸ” Raw trials response:", res['clinical_trials'])
196
  trials = res['clinical_trials']
197
  if not trials:
198
  st.info("No trials returned (rate-limited or none found).")
 
203
  f"Phase {t.get('phase','?')} | Status {t.get('status','?')}"
204
  )
205
 
206
+ # --- Variants tab ---
207
  with tabs[3]:
208
  st.header("Cancer variants (cBioPortal)")
209
+ # Debug: show raw response
210
+ st.write("πŸ” Raw variants response:", res['variants'])
211
  variants = res['variants']
212
  if not variants:
213
  st.info("No variants for this gene/profile.")
214
  else:
215
  st.json(variants[:30])
216
 
217
+ # --- Graph tab ---
218
  with tabs[4]:
219
  nodes, edges, cfg = build_agraph(res['papers'], res['umls'], res['drug_safety'])
220
  agraph(nodes, edges, cfg)
221
 
222
+ # --- Metrics tab ---
223
  with tabs[5]:
224
  G = build_nx([n.__dict__ for n in nodes], [e.__dict__ for e in edges])
225
  st.metric("Density", f"{get_density(G):.3f}")
 
228
  lab = next((n.label for n in nodes if n.id == nid), nid)
229
  st.write(f"- {lab} {sc:.3f}")
230
 
231
+ # --- Visuals tab ---
232
  with tabs[6]:
233
  years = [p.get('published') for p in res['papers'] if p.get('published')]
234
  if years:
235
  st.plotly_chart(px.histogram(years, nbins=12, title="Publication Year"))
236
 
237
+ # Follow-up QA (outside tabs)
238
  st.markdown("---")
239
  input_col, button_col = st.columns([4, 1])
240
  with input_col: