Update src/streamlit_app.py
Browse files- src/streamlit_app.py +276 -176
src/streamlit_app.py
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
-
import
|
|
|
|
|
|
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
# -----------------------------------------------------------------------------
|
| 7 |
-
# 0. AUTO-CONFIG
|
| 8 |
# -----------------------------------------------------------------------------
|
| 9 |
config_dir = ".streamlit"
|
| 10 |
if not os.path.exists(config_dir):
|
|
@@ -13,227 +16,324 @@ with open(os.path.join(config_dir, "config.toml"), "w") as f:
|
|
| 13 |
f.write("[server]\nenableXsrfProtection=false\nenableCORS=false\nmaxUploadSize=200\n")
|
| 14 |
|
| 15 |
# -----------------------------------------------------------------------------
|
| 16 |
-
# 1. SETUP
|
| 17 |
# -----------------------------------------------------------------------------
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
| 21 |
if not GOOGLE_API_KEY:
|
| 22 |
-
st.error("⚠️ Google API Key Missing
|
| 23 |
st.stop()
|
| 24 |
|
| 25 |
-
# Configure the standard library
|
| 26 |
genai.configure(api_key=GOOGLE_API_KEY)
|
|
|
|
| 27 |
|
| 28 |
# -----------------------------------------------------------------------------
|
| 29 |
-
#
|
| 30 |
# -----------------------------------------------------------------------------
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
# -----------------------------------------------------------------------------
|
| 34 |
-
# 2. STATE MANAGEMENT
|
| 35 |
-
# -----------------------------------------------------------------------------
|
| 36 |
-
if 'page' not in st.session_state: st.session_state.page = 'landing'
|
| 37 |
if 'logged_in' not in st.session_state: st.session_state.logged_in = False
|
| 38 |
-
if 'history' not in st.session_state: st.session_state.history = []
|
| 39 |
-
if 'result' not in st.session_state: st.session_state.result = None
|
| 40 |
if 'user_email' not in st.session_state: st.session_state.user_email = ""
|
|
|
|
| 41 |
|
| 42 |
# -----------------------------------------------------------------------------
|
| 43 |
-
#
|
| 44 |
# -----------------------------------------------------------------------------
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
"Analyze the input rigorously. Provide: "
|
| 49 |
-
"1. Detailed Observation, 2. Potential Risks/Differential Diagnosis, 3. Recommended Clinical Actions. "
|
| 50 |
-
"Maintain a highly professional, clinical tone."
|
| 51 |
-
)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
|
|
|
|
|
|
|
|
|
| 70 |
def nav_to(page):
|
| 71 |
st.session_state.page = page
|
| 72 |
st.rerun()
|
| 73 |
|
| 74 |
def sign_out():
|
| 75 |
st.session_state.logged_in = False
|
| 76 |
-
st.session_state.history = []
|
| 77 |
-
st.session_state.result = None
|
| 78 |
st.session_state.user_email = ""
|
| 79 |
-
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
-
#
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
# -----------------------------------------------------------------------------
|
| 96 |
-
#
|
| 97 |
# -----------------------------------------------------------------------------
|
| 98 |
|
| 99 |
-
# ---
|
| 100 |
-
def
|
| 101 |
-
c1, c2 = st.columns([1,
|
| 102 |
-
with c1: st.markdown("### ✨ Shinui")
|
| 103 |
-
st.markdown("<br><br>", unsafe_allow_html=True)
|
| 104 |
-
|
| 105 |
-
c1, c2 = st.columns([1.5, 1])
|
| 106 |
-
with c1:
|
| 107 |
-
st.markdown(f"""
|
| 108 |
-
<h1 style='font-size: 4rem; line-height: 1.1; margin-bottom: 20px;'>
|
| 109 |
-
Medical Intelligence.<br><span style='color:#38bdf8;'>Powered by Gemini 2.5 Pro.</span>
|
| 110 |
-
</h1>
|
| 111 |
-
<p style='font-size: 1.2rem; color: #94a3b8; margin-bottom: 40px;'>
|
| 112 |
-
High-fidelity multimodal analysis for complex clinical data.
|
| 113 |
-
</p>
|
| 114 |
-
""", unsafe_allow_html=True)
|
| 115 |
-
b1, b2 = st.columns([1, 2])
|
| 116 |
-
with b1:
|
| 117 |
-
if st.button("Sign In"): nav_to('login')
|
| 118 |
-
with b2:
|
| 119 |
-
if st.button("About System"): nav_to('about')
|
| 120 |
-
|
| 121 |
-
with c2:
|
| 122 |
-
st.markdown(f"""
|
| 123 |
-
<div class='shinui-card'>
|
| 124 |
-
<h3>🧬 Advanced Model Active</h3>
|
| 125 |
-
<p style='color:#94a3b8;'>Engine: <code>{MODEL_ID}</code></p>
|
| 126 |
-
<p style='color:#94a3b8; font-size: 0.9rem'>Optimized for deep reasoning & visual processing.</p>
|
| 127 |
-
</div>
|
| 128 |
-
""", unsafe_allow_html=True)
|
| 129 |
-
|
| 130 |
-
# --- ABOUT ---
|
| 131 |
-
def show_about():
|
| 132 |
-
if st.button("← Back Home"): nav_to('landing')
|
| 133 |
-
st.markdown("<br>", unsafe_allow_html=True)
|
| 134 |
-
st.markdown(f"""
|
| 135 |
-
<div class='shinui-card'>
|
| 136 |
-
<h2 style='color:#38bdf8'>About Shinui</h2>
|
| 137 |
-
<p style='font-size:1.1rem; line-height:1.6'>
|
| 138 |
-
Shinui is configured to use the high-performance <b>{MODEL_ID}</b> model.
|
| 139 |
-
Unlike lightweight "Flash" models, this engine is designed for complex reasoning tasks,
|
| 140 |
-
handling intricate medical imagery and detailed clinical notes with higher accuracy.
|
| 141 |
-
</p>
|
| 142 |
-
<hr style='border-color:#333'>
|
| 143 |
-
<h3>Capabilities</h3>
|
| 144 |
-
<ul>
|
| 145 |
-
<li><b>Deep Visual Reasoning:</b> Analyzing medical imaging with higher parameter counts.</li>
|
| 146 |
-
<li><b>Complex Context Window:</b> Processing long-form patient histories.</li>
|
| 147 |
-
</ul>
|
| 148 |
-
</div>
|
| 149 |
-
""", unsafe_allow_html=True)
|
| 150 |
-
|
| 151 |
-
# --- LOGIN ---
|
| 152 |
-
def show_login():
|
| 153 |
-
c1, c2, c3 = st.columns([1,1,1])
|
| 154 |
with c2:
|
| 155 |
st.markdown("<br><br>", unsafe_allow_html=True)
|
| 156 |
-
st.markdown("<
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
# --- DASHBOARD ---
|
| 167 |
def show_dashboard():
|
|
|
|
| 168 |
with st.sidebar:
|
| 169 |
st.markdown(f"### 👤 {st.session_state.user_email}")
|
| 170 |
-
|
| 171 |
st.markdown("---")
|
| 172 |
-
|
| 173 |
-
if st.
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
else:
|
| 177 |
-
st.caption("No
|
|
|
|
| 178 |
st.markdown("---")
|
| 179 |
if st.button("Sign Out"): sign_out()
|
| 180 |
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
with st.sidebar:
|
| 217 |
-
if st.button("← Back"): nav_to('dashboard')
|
| 218 |
-
|
|
|
|
| 219 |
<div class='shinui-card'>
|
| 220 |
-
<h2 style='color:#
|
| 221 |
-
<p
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
</div>
|
| 225 |
""", unsafe_allow_html=True)
|
| 226 |
|
| 227 |
# -----------------------------------------------------------------------------
|
| 228 |
-
#
|
| 229 |
# -----------------------------------------------------------------------------
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
|
|
|
| 233 |
elif st.session_state.page == 'dashboard':
|
| 234 |
if st.session_state.logged_in: show_dashboard()
|
| 235 |
-
else: nav_to('
|
| 236 |
-
elif st.session_state.page == '
|
| 237 |
-
if st.session_state.logged_in:
|
| 238 |
-
else: nav_to('
|
| 239 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
+
import sqlite3
|
| 4 |
+
import hashlib
|
| 5 |
+
import google.generativeai as genai
|
| 6 |
from PIL import Image
|
| 7 |
+
from datetime import datetime
|
| 8 |
|
| 9 |
# -----------------------------------------------------------------------------
|
| 10 |
+
# 0. AUTO-CONFIG (FIX UPLOAD ERROR)
|
| 11 |
# -----------------------------------------------------------------------------
|
| 12 |
config_dir = ".streamlit"
|
| 13 |
if not os.path.exists(config_dir):
|
|
|
|
| 16 |
f.write("[server]\nenableXsrfProtection=false\nenableCORS=false\nmaxUploadSize=200\n")
|
| 17 |
|
| 18 |
# -----------------------------------------------------------------------------
|
| 19 |
+
# 1. DATABASE SETUP (REAL USER SYSTEM)
|
| 20 |
# -----------------------------------------------------------------------------
|
| 21 |
+
def init_db():
|
| 22 |
+
conn = sqlite3.connect('users.db')
|
| 23 |
+
c = conn.cursor()
|
| 24 |
+
# Create users table
|
| 25 |
+
c.execute('''CREATE TABLE IF NOT EXISTS users
|
| 26 |
+
(email TEXT PRIMARY KEY, password TEXT, joined_date TEXT)''')
|
| 27 |
+
# Create history table
|
| 28 |
+
c.execute('''CREATE TABLE IF NOT EXISTS history
|
| 29 |
+
(id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT, type TEXT, summary TEXT, date TEXT)''')
|
| 30 |
+
conn.commit()
|
| 31 |
+
conn.close()
|
| 32 |
+
|
| 33 |
+
def hash_pass(password):
|
| 34 |
+
return hashlib.sha256(str.encode(password)).hexdigest()
|
| 35 |
+
|
| 36 |
+
def register_user(email, password):
|
| 37 |
+
conn = sqlite3.connect('users.db')
|
| 38 |
+
c = conn.cursor()
|
| 39 |
+
try:
|
| 40 |
+
c.execute("INSERT INTO users VALUES (?, ?, ?)", (email, hash_pass(password), datetime.now().strftime("%Y-%m-%d")))
|
| 41 |
+
conn.commit()
|
| 42 |
+
return True
|
| 43 |
+
except sqlite3.IntegrityError:
|
| 44 |
+
return False
|
| 45 |
+
finally:
|
| 46 |
+
conn.close()
|
| 47 |
+
|
| 48 |
+
def login_user(email, password):
|
| 49 |
+
conn = sqlite3.connect('users.db')
|
| 50 |
+
c = conn.cursor()
|
| 51 |
+
c.execute("SELECT * FROM users WHERE email=? AND password=?", (email, hash_pass(password)))
|
| 52 |
+
data = c.fetchall()
|
| 53 |
+
conn.close()
|
| 54 |
+
return data
|
| 55 |
+
|
| 56 |
+
def add_history(email, type, summary):
|
| 57 |
+
conn = sqlite3.connect('users.db')
|
| 58 |
+
c = conn.cursor()
|
| 59 |
+
c.execute("INSERT INTO history (email, type, summary, date) VALUES (?, ?, ?, ?)",
|
| 60 |
+
(email, type, summary, datetime.now().strftime("%Y-%m-%d %H:%M")))
|
| 61 |
+
conn.commit()
|
| 62 |
+
conn.close()
|
| 63 |
+
|
| 64 |
+
def get_history(email):
|
| 65 |
+
conn = sqlite3.connect('users.db')
|
| 66 |
+
c = conn.cursor()
|
| 67 |
+
c.execute("SELECT type, summary, date FROM history WHERE email=? ORDER BY id DESC LIMIT 10", (email,))
|
| 68 |
+
data = c.fetchall()
|
| 69 |
+
conn.close()
|
| 70 |
+
return data
|
| 71 |
+
|
| 72 |
+
# Initialize DB on startup
|
| 73 |
+
init_db()
|
| 74 |
+
|
| 75 |
+
# -----------------------------------------------------------------------------
|
| 76 |
+
# 2. AI CONFIGURATION
|
| 77 |
+
# -----------------------------------------------------------------------------
|
| 78 |
+
st.set_page_config(page_title="Shinui | Medical MVP", page_icon="✨", layout="wide")
|
| 79 |
|
| 80 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
| 81 |
if not GOOGLE_API_KEY:
|
| 82 |
+
st.error("⚠️ System Error: Google API Key Missing.")
|
| 83 |
st.stop()
|
| 84 |
|
|
|
|
| 85 |
genai.configure(api_key=GOOGLE_API_KEY)
|
| 86 |
+
model = genai.GenerativeModel('gemini-1.5-flash')
|
| 87 |
|
| 88 |
# -----------------------------------------------------------------------------
|
| 89 |
+
# 3. STATE MANAGEMENT
|
| 90 |
# -----------------------------------------------------------------------------
|
| 91 |
+
if 'page' not in st.session_state: st.session_state.page = 'auth'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
if 'logged_in' not in st.session_state: st.session_state.logged_in = False
|
|
|
|
|
|
|
| 93 |
if 'user_email' not in st.session_state: st.session_state.user_email = ""
|
| 94 |
+
if 'current_result' not in st.session_state: st.session_state.current_result = None
|
| 95 |
|
| 96 |
# -----------------------------------------------------------------------------
|
| 97 |
+
# 4. UI STYLING (PROFESSIONAL DARK MODE)
|
| 98 |
# -----------------------------------------------------------------------------
|
| 99 |
+
st.markdown("""
|
| 100 |
+
<style>
|
| 101 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;800&display=swap');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
.stApp {
|
| 104 |
+
background-color: #0f172a;
|
| 105 |
+
font-family: 'Inter', sans-serif;
|
| 106 |
+
color: #f8fafc;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/* Cards */
|
| 110 |
+
.shinui-card {
|
| 111 |
+
background: #1e293b;
|
| 112 |
+
border: 1px solid #334155;
|
| 113 |
+
border-radius: 12px;
|
| 114 |
+
padding: 24px;
|
| 115 |
+
margin-bottom: 20px;
|
| 116 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/* Buttons */
|
| 120 |
+
div.stButton > button {
|
| 121 |
+
background-color: #3b82f6;
|
| 122 |
+
color: white;
|
| 123 |
+
border-radius: 8px;
|
| 124 |
+
padding: 10px 24px;
|
| 125 |
+
font-weight: 600;
|
| 126 |
+
border: none;
|
| 127 |
+
width: 100%;
|
| 128 |
+
transition: all 0.2s;
|
| 129 |
+
}
|
| 130 |
+
div.stButton > button:hover {
|
| 131 |
+
background-color: #2563eb;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/* Results */
|
| 135 |
+
.result-section {
|
| 136 |
+
padding: 15px;
|
| 137 |
+
border-left: 4px solid #3b82f6;
|
| 138 |
+
background: rgba(59, 130, 246, 0.1);
|
| 139 |
+
margin-bottom: 10px;
|
| 140 |
+
border-radius: 0 8px 8px 0;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/* Inputs */
|
| 144 |
+
.stTextInput input {
|
| 145 |
+
background-color: #334155;
|
| 146 |
+
color: white;
|
| 147 |
+
border: 1px solid #475569;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
#MainMenu, footer, header {visibility: hidden;}
|
| 151 |
+
</style>
|
| 152 |
+
""", unsafe_allow_html=True)
|
| 153 |
|
| 154 |
+
# -----------------------------------------------------------------------------
|
| 155 |
+
# 5. LOGIC FUNCTIONS
|
| 156 |
+
# -----------------------------------------------------------------------------
|
| 157 |
def nav_to(page):
|
| 158 |
st.session_state.page = page
|
| 159 |
st.rerun()
|
| 160 |
|
| 161 |
def sign_out():
|
| 162 |
st.session_state.logged_in = False
|
|
|
|
|
|
|
| 163 |
st.session_state.user_email = ""
|
| 164 |
+
st.session_state.current_result = None
|
| 165 |
+
nav_to('auth')
|
| 166 |
|
| 167 |
+
def get_gemini_insight(input_type, content):
|
| 168 |
+
# Detailed MVP System Prompt
|
| 169 |
+
prompt = """
|
| 170 |
+
You are Shinui, a professional medical AI assistant.
|
| 171 |
+
Analyze the input carefully.
|
| 172 |
+
Format your response using these EXACT headers:
|
| 173 |
+
|
| 174 |
+
### 1. Clinical Observation
|
| 175 |
+
(Describe what you see or read clearly)
|
| 176 |
+
|
| 177 |
+
### 2. Potential Risks
|
| 178 |
+
(List potential conditions or risks associated)
|
| 179 |
+
|
| 180 |
+
### 3. Recommended Actions
|
| 181 |
+
(Suggest next steps, e.g., see a specialist, apply ice, etc.)
|
| 182 |
+
"""
|
| 183 |
+
|
| 184 |
+
try:
|
| 185 |
+
if input_type == "Image":
|
| 186 |
+
response = model.generate_content([prompt, content])
|
| 187 |
+
return response.text
|
| 188 |
+
elif input_type == "Text":
|
| 189 |
+
response = model.generate_content(f"{prompt}\n\nInput Data: {content}")
|
| 190 |
+
return response.text
|
| 191 |
+
except Exception as e:
|
| 192 |
+
return f"Error: {str(e)}"
|
| 193 |
|
| 194 |
# -----------------------------------------------------------------------------
|
| 195 |
+
# 6. PAGES
|
| 196 |
# -----------------------------------------------------------------------------
|
| 197 |
|
| 198 |
+
# --- AUTH PAGE (LOGIN / REGISTER) ---
|
| 199 |
+
def show_auth():
|
| 200 |
+
c1, c2, c3 = st.columns([1, 2, 1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
with c2:
|
| 202 |
st.markdown("<br><br>", unsafe_allow_html=True)
|
| 203 |
+
st.markdown("<h1 style='text-align:center; color:#3b82f6;'>✨ Shinui</h1>", unsafe_allow_html=True)
|
| 204 |
+
st.markdown("<p style='text-align:center; color:#94a3b8;'>Intelligent Medical Analysis MVP</p>", unsafe_allow_html=True)
|
| 205 |
+
|
| 206 |
+
tab1, tab2 = st.tabs(["Sign In", "Create Account"])
|
| 207 |
+
|
| 208 |
+
with tab1:
|
| 209 |
+
st.markdown("<div class='shinui-card'>", unsafe_allow_html=True)
|
| 210 |
+
email = st.text_input("Email Address", key="l_email")
|
| 211 |
+
password = st.text_input("Password", type="password", key="l_pass")
|
| 212 |
+
if st.button("Login"):
|
| 213 |
+
if login_user(email, password):
|
| 214 |
+
st.session_state.logged_in = True
|
| 215 |
+
st.session_state.user_email = email
|
| 216 |
+
st.success("Login Successful")
|
| 217 |
+
time.sleep(0.5) # Smooth transition
|
| 218 |
+
nav_to('dashboard')
|
| 219 |
+
else:
|
| 220 |
+
st.error("Invalid email or password")
|
| 221 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 222 |
+
|
| 223 |
+
with tab2:
|
| 224 |
+
st.markdown("<div class='shinui-card'>", unsafe_allow_html=True)
|
| 225 |
+
new_email = st.text_input("Email Address", key="r_email")
|
| 226 |
+
new_pass = st.text_input("Password", type="password", key="r_pass")
|
| 227 |
+
confirm_pass = st.text_input("Confirm Password", type="password", key="r_pass2")
|
| 228 |
+
if st.button("Register"):
|
| 229 |
+
if new_pass != confirm_pass:
|
| 230 |
+
st.error("Passwords do not match")
|
| 231 |
+
elif register_user(new_email, new_pass):
|
| 232 |
+
st.success("Account created! Please log in.")
|
| 233 |
+
else:
|
| 234 |
+
st.error("Email already exists")
|
| 235 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 236 |
|
| 237 |
# --- DASHBOARD ---
|
| 238 |
def show_dashboard():
|
| 239 |
+
# SIDEBAR NAVIGATION
|
| 240 |
with st.sidebar:
|
| 241 |
st.markdown(f"### 👤 {st.session_state.user_email}")
|
| 242 |
+
st.markdown("<span style='color:#22c55e; font-size:0.8rem;'>● Online</span>", unsafe_allow_html=True)
|
| 243 |
st.markdown("---")
|
| 244 |
+
|
| 245 |
+
if st.button("📊 Dashboard"): nav_to('dashboard')
|
| 246 |
+
if st.button("ℹ️ About Shinui"): nav_to('about')
|
| 247 |
+
|
| 248 |
+
st.markdown("### Recent History")
|
| 249 |
+
history = get_history(st.session_state.user_email)
|
| 250 |
+
if history:
|
| 251 |
+
for h_type, h_sum, h_date in history:
|
| 252 |
+
st.markdown(f"""
|
| 253 |
+
<div style='font-size:0.8rem; padding:8px; background:#334155; border-radius:6px; margin-bottom:6px;'>
|
| 254 |
+
<b>{h_type}</b><br>{h_date}<br><span style='color:#94a3b8'>{h_sum[:40]}...</span>
|
| 255 |
+
</div>
|
| 256 |
+
""", unsafe_allow_html=True)
|
| 257 |
else:
|
| 258 |
+
st.caption("No activity found.")
|
| 259 |
+
|
| 260 |
st.markdown("---")
|
| 261 |
if st.button("Sign Out"): sign_out()
|
| 262 |
|
| 263 |
+
# MAIN CONTENT
|
| 264 |
+
st.title("Medical Analysis Dashboard")
|
| 265 |
+
|
| 266 |
+
col1, col2 = st.columns([2, 1])
|
| 267 |
+
with col1:
|
| 268 |
+
st.markdown("### New Scan")
|
| 269 |
+
t1, t2 = st.tabs(["📷 Visual Analysis", "📝 Symptom Check"])
|
| 270 |
+
|
| 271 |
+
with t1:
|
| 272 |
+
st.markdown("<div class='shinui-card'>", unsafe_allow_html=True)
|
| 273 |
+
img = st.file_uploader("Upload Medical Image", type=['png','jpg','jpeg'])
|
| 274 |
+
if img and st.button("Analyze Image"):
|
| 275 |
+
image = Image.open(img)
|
| 276 |
+
with st.spinner("Shinui AI Analyzing..."):
|
| 277 |
+
res = get_gemini_insight("Image", image)
|
| 278 |
+
st.session_state.current_result = res
|
| 279 |
+
# Save detailed result to DB
|
| 280 |
+
add_history(st.session_state.user_email, "Visual Scan", res[:100].replace('\n', ' '))
|
| 281 |
+
|
| 282 |
+
with t2:
|
| 283 |
+
st.markdown("<div class='shinui-card'>", unsafe_allow_html=True)
|
| 284 |
+
txt = st.text_area("Describe Symptoms")
|
| 285 |
+
if txt and st.button("Analyze Text"):
|
| 286 |
+
with st.spinner("Shinui AI Analyzing..."):
|
| 287 |
+
res = get_gemini_insight("Text", txt)
|
| 288 |
+
st.session_state.current_result = res
|
| 289 |
+
add_history(st.session_state.user_email, "Text Analysis", res[:100].replace('\n', ' '))
|
| 290 |
+
|
| 291 |
+
# RESULTS SECTION (Right Side / Bottom)
|
| 292 |
+
with col2:
|
| 293 |
+
st.markdown("### Results")
|
| 294 |
+
if st.session_state.current_result:
|
| 295 |
+
# Parsing Markdown for pretty display
|
| 296 |
+
content = st.session_state.current_result
|
| 297 |
+
st.markdown(f"""
|
| 298 |
+
<div class='shinui-card' style='border-top: 4px solid #3b82f6;'>
|
| 299 |
+
{content}
|
| 300 |
+
</div>
|
| 301 |
+
""", unsafe_allow_html=True)
|
| 302 |
+
else:
|
| 303 |
+
st.info("Upload an image or enter text to see analysis results here.")
|
| 304 |
+
|
| 305 |
+
# --- ABOUT PAGE ---
|
| 306 |
+
def show_about():
|
| 307 |
with st.sidebar:
|
| 308 |
+
if st.button("← Back to Dashboard"): nav_to('dashboard')
|
| 309 |
+
|
| 310 |
+
st.markdown("""
|
| 311 |
<div class='shinui-card'>
|
| 312 |
+
<h2 style='color:#3b82f6'>About Shinui</h2>
|
| 313 |
+
<p style='font-size:1.1rem; line-height:1.6'>
|
| 314 |
+
Shinui is an MVP-stage medical intelligence platform designed to democratize access to health data analysis.
|
| 315 |
+
</p>
|
| 316 |
+
<hr style='border-color:#334155'>
|
| 317 |
+
<h3>The Problem</h3>
|
| 318 |
+
<p>Medical data is complex, jargon-heavy, and hard for patients to interpret.</p>
|
| 319 |
+
<h3>The Solution</h3>
|
| 320 |
+
<p>Shinui uses Google's Gemini 1.5 Flash model to act as a translator, turning images and clinical notes into actionable, understandable insights.</p>
|
| 321 |
+
<h3>Version Info</h3>
|
| 322 |
+
<p><b>Build:</b> v1.0 MVP</p>
|
| 323 |
+
<p><b>Engine:</b> Gemini 1.5 Flash</p>
|
| 324 |
</div>
|
| 325 |
""", unsafe_allow_html=True)
|
| 326 |
|
| 327 |
# -----------------------------------------------------------------------------
|
| 328 |
+
# 7. ROUTER
|
| 329 |
# -----------------------------------------------------------------------------
|
| 330 |
+
import time # Import needed for sleep
|
| 331 |
+
|
| 332 |
+
if st.session_state.page == 'auth':
|
| 333 |
+
show_auth()
|
| 334 |
elif st.session_state.page == 'dashboard':
|
| 335 |
if st.session_state.logged_in: show_dashboard()
|
| 336 |
+
else: nav_to('auth')
|
| 337 |
+
elif st.session_state.page == 'about':
|
| 338 |
+
if st.session_state.logged_in: show_about()
|
| 339 |
+
else: nav_to('auth')
|
|
|