Update app.py
Browse files
app.py
CHANGED
|
@@ -1,60 +1,50 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from
|
| 3 |
-
from
|
| 4 |
-
from
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
if
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
st.info("No BioPortal concepts found.")
|
| 52 |
-
|
| 53 |
-
if run_quantum and query.strip():
|
| 54 |
-
with st.spinner("Quantum optimizer working..."):
|
| 55 |
-
plan = optimize_treatment(query)
|
| 56 |
-
st.markdown("### 𧬠Optimized Care Plan")
|
| 57 |
-
st.json(plan)
|
| 58 |
-
|
| 59 |
-
st.markdown("---")
|
| 60 |
-
st.caption("Powered by Gemini LLM, UMLS, BioPortal, and quantum-inspired algorithms. For research use only. No patient data is stored.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from services.auth import authenticator, require_login
|
| 3 |
+
from services.logger import logger
|
| 4 |
+
from services.metrics import CHAT_COUNT, OPTIMIZE_COUNT
|
| 5 |
+
from agent.gemini_agent import chat_with_gemini
|
| 6 |
+
from clinical_nlp.umls_bioportal import lookup_umls, lookup_bioportal
|
| 7 |
+
from quantum.bf_dcqo import optimize_hubo
|
| 8 |
+
from services.pdf_report import generate_pdf
|
| 9 |
+
from repositories.chat_repo import ChatRepo
|
| 10 |
+
|
| 11 |
+
# Initialize DB
|
| 12 |
+
from models.db import init_db
|
| 13 |
+
init_db()
|
| 14 |
+
|
| 15 |
+
# UI
|
| 16 |
+
username = require_login()
|
| 17 |
+
st.set_page_config(page_title="Quantum Health AI", layout="wide")
|
| 18 |
+
st.image("assets/logo.png", width=64)
|
| 19 |
+
st.title(f"Welcome, {username}!")
|
| 20 |
+
|
| 21 |
+
tab1, tab2 = st.tabs(["π©Ί Consult", "π Reports"])
|
| 22 |
+
|
| 23 |
+
with tab1:
|
| 24 |
+
query = st.text_area("Enter clinical query or symptoms:")
|
| 25 |
+
if st.button("Ask Gemini"):
|
| 26 |
+
CHAT_COUNT.inc()
|
| 27 |
+
with st.spinner("Consulting AI..."):
|
| 28 |
+
response = chat_with_gemini(username, query)
|
| 29 |
+
st.markdown(f"**AI**: {response}")
|
| 30 |
+
# save chat
|
| 31 |
+
ChatRepo().save(username, query, response)
|
| 32 |
+
# clinical NLP
|
| 33 |
+
with st.expander("UMLS Results"):
|
| 34 |
+
st.write(lookup_umls(query))
|
| 35 |
+
with st.expander("BioPortal Results"):
|
| 36 |
+
st.write(lookup_bioportal(query))
|
| 37 |
+
|
| 38 |
+
if st.button("Quantum Optimize"):
|
| 39 |
+
OPTIMIZE_COUNT.inc()
|
| 40 |
+
with st.spinner("Running quantum optimizer..."):
|
| 41 |
+
result = optimize_hubo({"query":query})
|
| 42 |
+
st.json(result)
|
| 43 |
+
|
| 44 |
+
with tab2:
|
| 45 |
+
if st.button("Generate PDF Report"):
|
| 46 |
+
# gather last 5 messages
|
| 47 |
+
pdf_data = {"Last Chats": ChatRepo().get_recent(username, limit=5)}
|
| 48 |
+
fname = generate_pdf(pdf_data)
|
| 49 |
+
st.success("Report Generated")
|
| 50 |
+
st.download_button("Download Report", data=open(fname,"rb"), file_name=fname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|