Update app.py
Browse files
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 |
-
#
|
11 |
-
|
12 |
-
api
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
#
|
|
|
23 |
def render_ui():
|
24 |
-
st.set_page_config(page_title="
|
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 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
results = orchestrate_search(query)
|
38 |
-
st.success("
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
st.
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
st.write(f"- {link}")
|
53 |
|
|
|
54 |
st.markdown("---")
|
55 |
-
st.subheader("
|
56 |
-
follow_up = st.text_input("
|
57 |
if st.button("Ask AI"):
|
58 |
-
with st.spinner("
|
59 |
-
|
60 |
-
st.success("AI
|
61 |
-
st.write(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|