mgbam commited on
Commit
31dadea
Β·
verified Β·
1 Parent(s): 48a3a15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -1
app.py CHANGED
@@ -6,10 +6,12 @@ from fastapi import FastAPI
6
  from fastapi.middleware.cors import CORSMiddleware
7
  from mcp.orchestrator import orchestrate_search, answer_ai_question
8
  from mcp.schemas import UnifiedSearchInput, UnifiedSearchResult
 
9
  from pathlib import Path
10
  import pandas as pd
11
  from fpdf import FPDF
12
  import asyncio
 
13
 
14
  ROOT_DIR = Path(__file__).resolve().parent
15
  LOGO_PATH = ROOT_DIR / "assets" / "logo.png"
@@ -60,7 +62,26 @@ def generate_pdf(papers):
60
  def render_ui():
61
  st.set_page_config(page_title="MedGenesis AI", layout="wide")
62
 
63
- # Header with logo and branding
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  col1, col2 = st.columns([0.15, 0.85])
65
  with col1:
66
  if LOGO_PATH.exists():
@@ -85,6 +106,7 @@ def render_ui():
85
  with st.spinner("Thinking... Gathering and analyzing data across 5 systems..."):
86
  results = asyncio.run(orchestrate_search(query))
87
  st.success("Search complete! πŸŽ‰")
 
88
 
89
  if results:
90
  # Papers
@@ -93,6 +115,12 @@ def render_ui():
93
  st.markdown(f"**{i}. [{paper['title']}]({paper['link']})** \n*{paper['authors']}* ({paper['source']})")
94
  st.markdown(f"<div style='font-size: 0.9em; color: gray'>{paper['summary']}</div>", unsafe_allow_html=True)
95
 
 
 
 
 
 
 
96
  # Export as CSV
97
  if results["papers"]:
98
  df = pd.DataFrame(results["papers"])
 
6
  from fastapi.middleware.cors import CORSMiddleware
7
  from mcp.orchestrator import orchestrate_search, answer_ai_question
8
  from mcp.schemas import UnifiedSearchInput, UnifiedSearchResult
9
+ from mcp.workspace import get_workspace, save_query
10
  from pathlib import Path
11
  import pandas as pd
12
  from fpdf import FPDF
13
  import asyncio
14
+ import plotly.express as px
15
 
16
  ROOT_DIR = Path(__file__).resolve().parent
17
  LOGO_PATH = ROOT_DIR / "assets" / "logo.png"
 
62
  def render_ui():
63
  st.set_page_config(page_title="MedGenesis AI", layout="wide")
64
 
65
+ # --- SIDEBAR WORKSPACE ---
66
+ with st.sidebar:
67
+ st.header("πŸ—‚οΈ Your Workspace")
68
+ saved_queries = get_workspace()
69
+ if saved_queries:
70
+ for i, item in enumerate(saved_queries, 1):
71
+ with st.expander(f"{i}. {item['query']}"):
72
+ st.write("**AI Summary:**", item["result"]["ai_summary"])
73
+ st.write("**First Paper:**", item["result"]["papers"][0]["title"] if item["result"]["papers"] else "None")
74
+ df = pd.DataFrame(item["result"]["papers"])
75
+ st.download_button(
76
+ label="πŸ“₯ Download as CSV",
77
+ data=df.to_csv(index=False),
78
+ file_name=f"workspace_query_{i}.csv",
79
+ mime="text/csv",
80
+ )
81
+ else:
82
+ st.info("Run a search and save it here!")
83
+
84
+ # --- MAIN APP HEADER ---
85
  col1, col2 = st.columns([0.15, 0.85])
86
  with col1:
87
  if LOGO_PATH.exists():
 
106
  with st.spinner("Thinking... Gathering and analyzing data across 5 systems..."):
107
  results = asyncio.run(orchestrate_search(query))
108
  st.success("Search complete! πŸŽ‰")
109
+ save_query(query, results) # Save to workspace
110
 
111
  if results:
112
  # Papers
 
115
  st.markdown(f"**{i}. [{paper['title']}]({paper['link']})** \n*{paper['authors']}* ({paper['source']})")
116
  st.markdown(f"<div style='font-size: 0.9em; color: gray'>{paper['summary']}</div>", unsafe_allow_html=True)
117
 
118
+ # --- INTERACTIVE VISUALIZATION: Publication Year Histogram ---
119
+ pub_years = [p["published"] for p in results["papers"] if p.get("published")]
120
+ if pub_years:
121
+ fig = px.histogram(pub_years, nbins=10, title="Publication Year Distribution")
122
+ st.plotly_chart(fig)
123
+
124
  # Export as CSV
125
  if results["papers"]:
126
  df = pd.DataFrame(results["papers"])