# app.py import os import streamlit as st from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from mcp.orchestrator import orchestrate_search, answer_ai_question from mcp.schemas import UnifiedSearchInput, UnifiedSearchResult from pathlib import Path import asyncio ROOT_DIR = Path(__file__).resolve().parent LOGO_PATH = ROOT_DIR / "assets" / "logo.png" # --- FASTAPI BACKEND --- api = FastAPI( title="MedGenesis MCP Server", version="2.0.0", description="MedGenesis AI unifies PubMed, ArXiv, OpenFDA, UMLS, and GPT-4o into a single biomedical intelligence platform." ) api.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) @api.post("/unified_search", response_model=UnifiedSearchResult) async def unified_search_endpoint(data: UnifiedSearchInput): return await orchestrate_search(data.query) @api.post("/ask_ai") async def ask_ai_endpoint(question: str, context: str = ""): return await answer_ai_question(question, context) # --- STREAMLIT UI --- def render_ui(): st.set_page_config(page_title="MedGenesis AI", layout="wide") # Header with logo and branding col1, col2 = st.columns([0.15, 0.85]) with col1: if LOGO_PATH.exists(): st.image(str(LOGO_PATH), width=100) else: st.markdown("🧬") with col2: st.markdown(""" ## 🧬 **MedGenesis AI** – Biomedical Research Reimagined *Unified Intelligence from PubMed, ArXiv, OpenFDA, UMLS, and GPT-4o* """) st.caption("Created by Oluwafemi Idiakhoa | Hugging Face Spaces") st.markdown("---") # Unified Semantic Search st.subheader("🔍 Unified Semantic Search") query = st.text_input("Enter your biomedical research question:", placeholder="e.g. New treatments for glioblastoma using CRISPR") if st.button("Run Search 🚀"): with st.spinner("Thinking... Gathering and analyzing data across 5 systems..."): results = asyncio.run(orchestrate_search(query)) st.success("Search complete! 🎉") # Papers st.markdown("### 📚 Most Relevant Papers") for i, paper in enumerate(results["papers"], 1): st.markdown(f"**{i}. [{paper['title']}]({paper['link']})** \n*{paper['authors']}* ({paper['source']})") st.markdown(f"