mgbam commited on
Commit
a31351f
Β·
verified Β·
1 Parent(s): 4d149fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -1,6 +1,6 @@
1
  #!/usr/bin/env python3
2
  """
3
- MedGenesis AI – Streamlit front‑end (v3)
4
  --------------------------------------
5
  Supports **OpenAI** and **Gemini** engines and the enriched backend
6
  payload introduced in orchestrator v3:
@@ -11,7 +11,7 @@ Tabs:
11
  """
12
 
13
  ##############################################################################
14
- #Β Std‑libΒ /Β third‑party
15
  ##############################################################################
16
  import os
17
  import pathlib
@@ -25,7 +25,7 @@ from fpdf import FPDF
25
  from streamlit_agraph import agraph
26
 
27
  ##############################################################################
28
- #Β Internal helpers
29
  ##############################################################################
30
  from mcp.orchestrator import orchestrate_search, answer_ai_question
31
  from mcp.workspace import get_workspace, save_query
@@ -47,11 +47,11 @@ ROOT = Path(__file__).parent
47
  LOGO = ROOT / "assets" / "logo.png"
48
 
49
  ##############################################################################
50
- #Β Utility helpers
51
  ##############################################################################
52
 
53
  def _latin1_safe(txt: str) -> str:
54
- """Coerce UTF‑8 β†’ Latin‑1 with replacement (for FPDF)."""
55
  return txt.encode("latin-1", "replace").decode("latin-1")
56
 
57
 
@@ -66,9 +66,7 @@ def _pdf(papers: list[dict]) -> bytes:
66
  pdf.set_font("Helvetica", "B", 11)
67
  pdf.multi_cell(0, 7, _latin1_safe(f"{i}. {p.get('title','')}"))
68
  pdf.set_font("Helvetica", "", 9)
69
- body = f"{p.get('authors','')}
70
- {p.get('summary','')}
71
- {p.get('link','')}\n"
72
  pdf.multi_cell(0, 6, _latin1_safe(body))
73
  pdf.ln(1)
74
  return pdf.output(dest="S").encode("latin-1", "replace")
@@ -86,13 +84,13 @@ def _workspace_sidebar():
86
  st.write(item['result']['ai_summary'])
87
 
88
  ##############################################################################
89
- #Β Main UI renderer
90
  ##############################################################################
91
 
92
  def render_ui():
93
  st.set_page_config("MedGenesis AI", layout="wide")
94
 
95
- # Session‑state defaults
96
  defaults = dict(
97
  query_result=None,
98
  followup_input="",
@@ -112,7 +110,7 @@ def render_ui():
112
  st.image(str(LOGO), width=105)
113
  with col2:
114
  st.markdown("## 🧬 **MedGenesis AI**")
115
- st.caption("Multi‑source biomedical assistant Β· OpenAI / Gemini")
116
 
117
  # Controls
118
  engine = st.radio("LLM engine", ["openai", "gemini"], horizontal=True)
@@ -197,7 +195,7 @@ def render_ui():
197
  st.header("Clinical trials")
198
  trials = res['clinical_trials']
199
  if not trials:
200
- st.info("No trials returned (rate‑limited or none found).")
201
  for t in trials:
202
  st.markdown(f"**{t.get('nctId','')}** – {t.get('briefTitle','')} Phase {t.get('phase','?')} | Status {t.get('status','?')}")
203
 
@@ -230,9 +228,9 @@ def render_ui():
230
  if years:
231
  st.plotly_chart(px.histogram(years, nbins=12, title="Publication Year"))
232
 
233
- # Follow‑up QA
234
  st.markdown("---")
235
- st.text_input("Ask follow‑up question:", key="followup_input")
236
 
237
  def _on_ask():
238
  q = st.session_state.followup_input
@@ -248,7 +246,7 @@ def render_ui():
248
  st.write(st.session_state.followup_response)
249
 
250
  ##############################################################################
251
- #Β Entrypoint
252
  ##############################################################################
253
  if __name__ == "__main__":
254
- render_ui()
 
1
  #!/usr/bin/env python3
2
  """
3
+ MedGenesis AI – Streamlit front-end (v3)
4
  --------------------------------------
5
  Supports **OpenAI** and **Gemini** engines and the enriched backend
6
  payload introduced in orchestrator v3:
 
11
  """
12
 
13
  ##############################################################################
14
+ # Std-lib / third-party
15
  ##############################################################################
16
  import os
17
  import pathlib
 
25
  from streamlit_agraph import agraph
26
 
27
  ##############################################################################
28
+ # Internal helpers
29
  ##############################################################################
30
  from mcp.orchestrator import orchestrate_search, answer_ai_question
31
  from mcp.workspace import get_workspace, save_query
 
47
  LOGO = ROOT / "assets" / "logo.png"
48
 
49
  ##############################################################################
50
+ # Utility helpers
51
  ##############################################################################
52
 
53
  def _latin1_safe(txt: str) -> str:
54
+ """Coerce UTF-8 β†’ Latin-1 with replacement (for FPDF)."""
55
  return txt.encode("latin-1", "replace").decode("latin-1")
56
 
57
 
 
66
  pdf.set_font("Helvetica", "B", 11)
67
  pdf.multi_cell(0, 7, _latin1_safe(f"{i}. {p.get('title','')}"))
68
  pdf.set_font("Helvetica", "", 9)
69
+ body = f"{p.get('authors','')}\n{p.get('summary','')}\n{p.get('link','')}\n"
 
 
70
  pdf.multi_cell(0, 6, _latin1_safe(body))
71
  pdf.ln(1)
72
  return pdf.output(dest="S").encode("latin-1", "replace")
 
84
  st.write(item['result']['ai_summary'])
85
 
86
  ##############################################################################
87
+ # Main UI renderer
88
  ##############################################################################
89
 
90
  def render_ui():
91
  st.set_page_config("MedGenesis AI", layout="wide")
92
 
93
+ # Session-state defaults
94
  defaults = dict(
95
  query_result=None,
96
  followup_input="",
 
110
  st.image(str(LOGO), width=105)
111
  with col2:
112
  st.markdown("## 🧬 **MedGenesis AI**")
113
+ st.caption("Multi-source biomedical assistant Β· OpenAI / Gemini")
114
 
115
  # Controls
116
  engine = st.radio("LLM engine", ["openai", "gemini"], horizontal=True)
 
195
  st.header("Clinical trials")
196
  trials = res['clinical_trials']
197
  if not trials:
198
+ st.info("No trials returned (rate-limited or none found).")
199
  for t in trials:
200
  st.markdown(f"**{t.get('nctId','')}** – {t.get('briefTitle','')} Phase {t.get('phase','?')} | Status {t.get('status','?')}")
201
 
 
228
  if years:
229
  st.plotly_chart(px.histogram(years, nbins=12, title="Publication Year"))
230
 
231
+ # Follow-up QA
232
  st.markdown("---")
233
+ st.text_input("Ask follow-up question:", key="followup_input")
234
 
235
  def _on_ask():
236
  q = st.session_state.followup_input
 
246
  st.write(st.session_state.followup_response)
247
 
248
  ##############################################################################
249
+ # Entrypoint
250
  ##############################################################################
251
  if __name__ == "__main__":
252
+ render_ui()