|
import streamlit as st |
|
|
|
|
|
from models.db import init_db |
|
init_db() |
|
|
|
|
|
from services.auth import authenticator, require_login |
|
|
|
|
|
from agent.gemini_agent import chat_with_gemini |
|
from clinical_nlp.umls_bioportal import lookup_umls, lookup_bioportal |
|
from quantum.optimizer import optimize_treatment |
|
from repositories.chat_repo import ChatRepo |
|
|
|
|
|
from services.logger import logger |
|
from services.metrics import CHAT_COUNT, OPTIMIZE_COUNT |
|
|
|
|
|
username = require_login() |
|
st.set_page_config(page_title="Quantum Health AI", layout="wide") |
|
st.image("assets/logo.png", width=64) |
|
st.title(f"Welcome, {username}!") |
|
|
|
tab1, tab2 = st.tabs(["π©Ί Consult", "π Reports"]) |
|
|
|
with tab1: |
|
query = st.text_area("Describe symptoms or enter a medical question:", height=100) |
|
|
|
if st.button("Ask Gemini"): |
|
CHAT_COUNT.inc() |
|
with st.spinner("Consulting AI..."): |
|
response = chat_with_gemini(username, query) |
|
logger.info(f"[Chat] user={username} prompt={query}") |
|
st.markdown(f"**AI Response:** {response}") |
|
ChatRepo().save(user=username, prompt=query, response=response) |
|
|
|
with st.expander("π UMLS Concept Lookup"): |
|
umls_res = lookup_umls(query) |
|
st.write(umls_res or "No UMLS concepts found.") |
|
|
|
with st.expander("π¬ BioPortal Concept Lookup"): |
|
bio_res = lookup_bioportal(query) |
|
st.write(bio_res or "No BioPortal matches found.") |
|
|
|
if st.button("Quantum Optimize Care Plan"): |
|
OPTIMIZE_COUNT.inc() |
|
with st.spinner("Running quantum-inspired optimizer..."): |
|
plan = optimize_treatment(query) |
|
logger.info(f"[Optimize] user={username} plan={plan}") |
|
st.markdown("### 𧬠Optimized Treatment Plan") |
|
st.json(plan) |
|
|
|
with tab2: |
|
st.header("Generate PDF Report of Recent Chats") |
|
if st.button("Download Last 5 Chats"): |
|
recent = ChatRepo().get_recent(user=username, limit=5) |
|
from services.pdf_report import generate_pdf |
|
pdf_path = generate_pdf({"Recent Chats": recent}) |
|
with open(pdf_path, "rb") as f: |
|
st.download_button("Download PDF", f, file_name=pdf_path) |
|
|
|
st.markdown("---") |
|
st.caption("Powered by Gemini LLM β’ UMLS/BioPortal β’ Quantum-inspired optimization") |
|
|