mgbam commited on
Commit
42d374e
Β·
verified Β·
1 Parent(s): 9d80717

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -36
app.py CHANGED
@@ -7,9 +7,21 @@ from fastapi.middleware.cors import CORSMiddleware
7
  from mcp.orchestrator import orchestrate_search, answer_ai_question
8
  from mcp.schemas import UnifiedSearchInput, UnifiedSearchResult
9
 
10
- # Initialize FastAPI app for API users
11
- api = FastAPI(title="MCP Research Server", version="2.0")
12
- api.add_middleware(CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"])
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  @api.post("/unified_search", response_model=UnifiedSearchResult)
15
  async def unified_search_endpoint(data: UnifiedSearchInput):
@@ -19,46 +31,79 @@ async def unified_search_endpoint(data: UnifiedSearchInput):
19
  async def ask_ai_endpoint(question: str, context: str = ""):
20
  return await answer_ai_question(question, context)
21
 
22
- # Streamlit UI for Hugging Face Space
 
23
  def render_ui():
24
- st.set_page_config(page_title="Ultimate Research Assistant", page_icon=":microscope:", layout="wide")
25
- st.image("assets/logo.png", width=100)
26
- st.title("πŸ”¬ Next-Gen AI-Powered Biomedical Research Assistant")
27
- st.markdown(
28
- """
29
- *Combine the power of ArXiv, PubMed, UMLS, OpenFDA, and OpenAI.
30
- Get instant, unified, semantically-ranked answersβ€”plus drug safety, concept enrichment, and expert Q&A!*
31
- """
32
- )
33
 
34
- query = st.text_input("Enter your research question or topic:", value="What are the latest treatments for Alzheimer's disease?")
35
- if st.button("Run Unified Search πŸš€"):
36
- with st.spinner("Retrieving and synthesizing knowledge..."):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  results = orchestrate_search(query)
38
- st.success("Here are the results!")
39
- for i, paper in enumerate(results['papers'], 1):
40
- st.markdown(f"**{i}. [{paper['title']}]({paper['link']})** \n*{paper['authors']}*")
41
- st.write(paper['summary'])
42
- st.subheader("UMLS Concept Enrichment")
43
- for c in results['umls']:
44
- st.write(f"**{c['name']}** (CUI: {c['cui']}): {c['definition']}")
45
- st.subheader("Drug & Safety Insights")
46
- for d in results['drug_safety']:
47
- st.write(d)
48
- st.subheader("AI-Generated Synthesis")
49
- st.info(results['ai_summary'])
50
- st.markdown("#### πŸ“š Suggested Reading")
51
- for link in results['suggested_reading']:
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  st.write(f"- {link}")
53
 
 
54
  st.markdown("---")
55
- st.subheader("πŸ€– Ask a follow-up (AI Q&A):")
56
- follow_up = st.text_input("Type your question here:")
57
  if st.button("Ask AI"):
58
- with st.spinner("AI is thinking..."):
59
- answer = answer_ai_question(follow_up, context=query)
60
- st.success("AI says:")
61
- st.write(answer['answer'])
 
 
 
 
 
 
 
 
 
 
62
 
63
  if __name__ == "__main__":
64
  import sys
 
7
  from mcp.orchestrator import orchestrate_search, answer_ai_question
8
  from mcp.schemas import UnifiedSearchInput, UnifiedSearchResult
9
 
10
+ # --- FASTAPI BACKEND ---
11
+
12
+ api = FastAPI(
13
+ title="Ultimate Research MCP Server",
14
+ version="2.0.0",
15
+ description="AI-powered unified biomedical search using ArXiv, PubMed, OpenFDA, UMLS, and OpenAI."
16
+ )
17
+
18
+ api.add_middleware(
19
+ CORSMiddleware,
20
+ allow_origins=["*"],
21
+ allow_credentials=True,
22
+ allow_methods=["*"],
23
+ allow_headers=["*"],
24
+ )
25
 
26
  @api.post("/unified_search", response_model=UnifiedSearchResult)
27
  async def unified_search_endpoint(data: UnifiedSearchInput):
 
31
  async def ask_ai_endpoint(question: str, context: str = ""):
32
  return await answer_ai_question(question, context)
33
 
34
+ # --- STREAMLIT UI ---
35
+
36
  def render_ui():
37
+ st.set_page_config(page_title="Neo Cures AI", layout="wide")
 
 
 
 
 
 
 
 
38
 
39
+ # Header with logo
40
+ col1, col2 = st.columns([0.15, 0.85])
41
+ with col1:
42
+ st.image("assets/logo.png", width=100)
43
+ with col2:
44
+ st.markdown("""
45
+ ## 🧬 **Neo Cures AI** – Advanced Biomedical Research Assistant
46
+ *Powered by GPT-4o, PubMed, ArXiv, OpenFDA, and UMLS*
47
+ """)
48
+ st.caption("Built by Oluwafemi Idiakhoa | Hugging Face Spaces")
49
+
50
+ st.markdown("---")
51
+
52
+ # Unified Semantic Search
53
+ st.subheader("πŸ” Unified Semantic Search")
54
+ query = st.text_input("Enter your biomedical research question:", placeholder="e.g. New treatments for glioblastoma using CRISPR")
55
+
56
+ if st.button("Run Search πŸš€"):
57
+ with st.spinner("Thinking... Gathering and analyzing data across 5 systems..."):
58
  results = orchestrate_search(query)
59
+ st.success("Search complete! πŸŽ‰")
60
+
61
+ # Papers
62
+ st.markdown("### πŸ“š Most Relevant Papers")
63
+ for i, paper in enumerate(results["papers"], 1):
64
+ st.markdown(f"**{i}. [{paper['title']}]({paper['link']})** \n*{paper['authors']}* ({paper['source']})")
65
+ st.markdown(f"<div style='font-size: 0.9em; color: gray'>{paper['summary']}</div>", unsafe_allow_html=True)
66
+
67
+ # UMLS Concepts
68
+ st.markdown("### 🧠 Biomedical Concept Enrichment (UMLS)")
69
+ for concept in results["umls"]:
70
+ if concept["cui"]:
71
+ st.markdown(f"πŸ”Ή **{concept['name']}** (CUI: `{concept['cui']}`): {concept['definition'] or 'No definition available'}")
72
+
73
+ # Drug Safety
74
+ st.markdown("### πŸ’Š Drug Safety Insights (OpenFDA)")
75
+ for drug_report in results["drug_safety"]:
76
+ if drug_report:
77
+ st.json(drug_report)
78
+
79
+ # AI Summary
80
+ st.markdown("### πŸ€– AI-Powered Summary")
81
+ st.info(results["ai_summary"])
82
+
83
+ # Suggested Reading
84
+ st.markdown("### πŸ“– Suggested Links")
85
+ for link in results["suggested_reading"]:
86
  st.write(f"- {link}")
87
 
88
+ # Follow-up AI Q&A
89
  st.markdown("---")
90
+ st.subheader("πŸ’¬ Ask AI a Follow-up Question")
91
+ follow_up = st.text_input("What do you want to ask based on the above?", placeholder="e.g. What's the most promising therapy?")
92
  if st.button("Ask AI"):
93
+ with st.spinner("Analyzing and responding..."):
94
+ ai_answer = answer_ai_question(follow_up, context=query)
95
+ st.success("AI's Response:")
96
+ st.write(ai_answer["answer"])
97
+
98
+ # Footer
99
+ st.markdown("---")
100
+ st.markdown(
101
+ "<div style='text-align: center; font-size: 0.9em;'>"
102
+ "✨ Built with ❀️ by <strong>Oluwafemi Idiakhoa</strong> β€’ Powered by FastAPI, Streamlit, Hugging Face, OpenAI, UMLS, OpenFDA, and NCBI</div>",
103
+ unsafe_allow_html=True
104
+ )
105
+
106
+ # --- MAIN ENTRY ---
107
 
108
  if __name__ == "__main__":
109
  import sys