mgbam commited on
Commit
864b488
Β·
verified Β·
1 Parent(s): 41b05bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -9
app.py CHANGED
@@ -4,8 +4,30 @@ import streamlit as st
4
  from models.db import init_db
5
  init_db()
6
 
7
- # 2) Auth
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  from services.auth import authenticator, require_login
 
9
 
10
  # 3) Core AI + Clinical NLP + Quantum
11
  from agent.gemini_agent import chat_with_gemini
@@ -17,8 +39,7 @@ from repositories.chat_repo import ChatRepo
17
  from services.logger import logger
18
  from services.metrics import CHAT_COUNT, OPTIMIZE_COUNT
19
 
20
- # β€”β€”β€” UI β€”β€”β€”
21
- username = require_login()
22
  st.set_page_config(page_title="Quantum Health AI", layout="wide")
23
  st.image("assets/logo.png", width=64)
24
  st.title(f"Welcome, {username}!")
@@ -26,7 +47,7 @@ st.title(f"Welcome, {username}!")
26
  tab1, tab2 = st.tabs(["🩺 Consult", "πŸ“Š Reports"])
27
 
28
  with tab1:
29
- query = st.text_area("Describe symptoms or enter a medical question:", height=100)
30
 
31
  if st.button("Ask Gemini"):
32
  CHAT_COUNT.inc()
@@ -37,12 +58,10 @@ with tab1:
37
  ChatRepo().save(user=username, prompt=query, response=response)
38
 
39
  with st.expander("πŸ”Ž UMLS Concept Lookup"):
40
- umls_res = lookup_umls(query)
41
- st.write(umls_res or "No UMLS concepts found.")
42
 
43
  with st.expander("πŸ”¬ BioPortal Concept Lookup"):
44
- bio_res = lookup_bioportal(query)
45
- st.write(bio_res or "No BioPortal matches found.")
46
 
47
  if st.button("Quantum Optimize Care Plan"):
48
  OPTIMIZE_COUNT.inc()
@@ -62,4 +81,4 @@ with tab2:
62
  st.download_button("Download PDF", f, file_name=pdf_path)
63
 
64
  st.markdown("---")
65
- st.caption("Powered by Gemini LLM β€’ UMLS/BioPortal β€’ Quantum-inspired optimization")
 
4
  from models.db import init_db
5
  init_db()
6
 
7
+ # β€”β€”β€”β€”β€” First-Run Signup Flow β€”β€”β€”β€”β€”
8
+ from repositories.user_repo import UserRepo
9
+ from config.settings import settings
10
+
11
+ repo = UserRepo(settings.database_url)
12
+ if not repo.get_all_users():
13
+ st.title("πŸš€ Welcome to Quantum Healthcare AI")
14
+ st.warning("No users exist yet. Please create the first admin account:")
15
+ new_user = st.text_input("Username")
16
+ new_name = st.text_input("Full name")
17
+ new_pw = st.text_input("Password", type="password")
18
+ if st.button("Create Admin User"):
19
+ if new_user and new_name and new_pw:
20
+ repo.add_user(new_user, new_name, new_pw)
21
+ st.success(f"Admin `{new_user}` created! Please refresh to log in.")
22
+ else:
23
+ st.error("All fields are required.")
24
+ # Stop here until admin is created
25
+ st.stop()
26
+ # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
27
+
28
+ # 2) Authentication (after at least one user exists)
29
  from services.auth import authenticator, require_login
30
+ username = require_login()
31
 
32
  # 3) Core AI + Clinical NLP + Quantum
33
  from agent.gemini_agent import chat_with_gemini
 
39
  from services.logger import logger
40
  from services.metrics import CHAT_COUNT, OPTIMIZE_COUNT
41
 
42
+ # === UI Setup ===
 
43
  st.set_page_config(page_title="Quantum Health AI", layout="wide")
44
  st.image("assets/logo.png", width=64)
45
  st.title(f"Welcome, {username}!")
 
47
  tab1, tab2 = st.tabs(["🩺 Consult", "πŸ“Š Reports"])
48
 
49
  with tab1:
50
+ query = st.text_area("Describe symptoms or ask a medical question:", height=100)
51
 
52
  if st.button("Ask Gemini"):
53
  CHAT_COUNT.inc()
 
58
  ChatRepo().save(user=username, prompt=query, response=response)
59
 
60
  with st.expander("πŸ”Ž UMLS Concept Lookup"):
61
+ st.write(lookup_umls(query) or "No UMLS concepts found.")
 
62
 
63
  with st.expander("πŸ”¬ BioPortal Concept Lookup"):
64
+ st.write(lookup_bioportal(query) or "No BioPortal matches found.")
 
65
 
66
  if st.button("Quantum Optimize Care Plan"):
67
  OPTIMIZE_COUNT.inc()
 
81
  st.download_button("Download PDF", f, file_name=pdf_path)
82
 
83
  st.markdown("---")
84
+ st.caption("Powered by Gemini LLM β€’ UMLS/BioPortal β€’ Quantum-inspired optimization")