Pontonkid commited on
Commit
c42c62f
·
verified ·
1 Parent(s): 5efbf80

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +54 -46
src/streamlit_app.py CHANGED
@@ -1,7 +1,6 @@
1
  import streamlit as st
2
  import os
3
- from google import genai
4
- from google.genai import types
5
  from PIL import Image
6
 
7
  # -----------------------------------------------------------------------------
@@ -14,7 +13,7 @@ with open(os.path.join(config_dir, "config.toml"), "w") as f:
14
  f.write("[server]\nenableXsrfProtection=false\nenableCORS=false\nmaxUploadSize=200\n")
15
 
16
  # -----------------------------------------------------------------------------
17
- # 1. SETUP & GOOGLE API (NEW SDK)
18
  # -----------------------------------------------------------------------------
19
  st.set_page_config(page_title="Shinui | Medical AI", page_icon="✨", layout="wide")
20
 
@@ -23,14 +22,16 @@ if not GOOGLE_API_KEY:
23
  st.error("⚠️ Google API Key Missing in Secrets.")
24
  st.stop()
25
 
26
- # Initialize the new GenAI Client
27
- client = genai.Client(api_key=GOOGLE_API_KEY)
28
 
29
- # You can switch this string to 'gemma-3-27b-it' if you prefer Gemma
30
- MODEL_ID = "gemini-2.5-pro"
 
 
31
 
32
  # -----------------------------------------------------------------------------
33
- # 2. STATE
34
  # -----------------------------------------------------------------------------
35
  if 'page' not in st.session_state: st.session_state.page = 'landing'
36
  if 'logged_in' not in st.session_state: st.session_state.logged_in = False
@@ -42,27 +43,29 @@ if 'user_email' not in st.session_state: st.session_state.user_email = ""
42
  # 3. LOGIC
43
  # -----------------------------------------------------------------------------
44
  def get_insight(input_type, content):
45
- system_instruction = "You are Shinui, a medical AI assistant. Analyze the input. Provide: 1. Observation, 2. Potential Risks, 3. Recommended Actions. Keep it professional."
 
 
 
 
 
46
 
47
  try:
 
 
 
48
  if input_type == "Image":
49
- # The new SDK handles PIL images directly in the contents list
50
- response = client.models.generate_content(
51
- model=MODEL_ID,
52
- contents=[system_instruction, content]
53
- )
54
  return response.text
55
 
56
  elif input_type == "Text":
57
- full_prompt = f"{system_instruction}\n\nPatient Notes: {content}"
58
- response = client.models.generate_content(
59
- model=MODEL_ID,
60
- contents=full_prompt
61
- )
62
  return response.text
63
 
64
  except Exception as e:
65
- return f"Error: {str(e)}"
66
 
67
  def nav_to(page):
68
  st.session_state.page = page
@@ -84,6 +87,7 @@ st.markdown("""
84
  .stApp { background-color: #020617; font-family: 'Plus Jakarta Sans', sans-serif; color: #f8fafc; }
85
  .shinui-card { background: rgba(30, 41, 59, 0.4); border: 1px solid rgba(148, 163, 184, 0.1); border-radius: 16px; padding: 25px; margin-bottom: 20px; }
86
  div.stButton > button { background: #38bdf8; color: #0f172a; border: none; font-weight: 700; padding: 12px 20px; border-radius: 8px; width: 100%; }
 
87
  #MainMenu, footer, header {visibility: hidden;}
88
  </style>
89
  """, unsafe_allow_html=True)
@@ -102,23 +106,24 @@ def show_landing():
102
  with c1:
103
  st.markdown(f"""
104
  <h1 style='font-size: 4rem; line-height: 1.1; margin-bottom: 20px;'>
105
- Medical Intelligence.<br><span style='color:#38bdf8;'>Powered by {MODEL_ID.title()}.</span>
106
  </h1>
107
  <p style='font-size: 1.2rem; color: #94a3b8; margin-bottom: 40px;'>
108
- Shinui analyzes medical data instantly using multimodal AI.
109
  </p>
110
  """, unsafe_allow_html=True)
111
  b1, b2 = st.columns([1, 2])
112
  with b1:
113
  if st.button("Sign In"): nav_to('login')
114
  with b2:
115
- if st.button("About Shinui"): nav_to('about')
116
 
117
  with c2:
118
  st.markdown(f"""
119
  <div class='shinui-card'>
120
- <h3>🧬 Powered by Google GenAI</h3>
121
- <p style='color:#94a3b8;'>Running on {MODEL_ID}</p>
 
122
  </div>
123
  """, unsafe_allow_html=True)
124
 
@@ -130,14 +135,15 @@ def show_about():
130
  <div class='shinui-card'>
131
  <h2 style='color:#38bdf8'>About Shinui</h2>
132
  <p style='font-size:1.1rem; line-height:1.6'>
133
- Shinui creates tools that bridge the gap between complex medical data and human understanding.
134
- By leveraging Google's <b>{MODEL_ID}</b> architecture, we provide instant analysis for images and text.
 
135
  </p>
136
  <hr style='border-color:#333'>
137
- <h3>Core Features</h3>
138
  <ul>
139
- <li><b>Visual Analysis:</b> Interpretation of scans, labels, and skin conditions.</li>
140
- <li><b>Clinical NLP:</b> Processing of complex medical notes and symptoms.</li>
141
  </ul>
142
  </div>
143
  """, unsafe_allow_html=True)
@@ -161,46 +167,46 @@ def show_login():
161
  def show_dashboard():
162
  with st.sidebar:
163
  st.markdown(f"### 👤 {st.session_state.user_email}")
164
- if st.button("About System"): nav_to('about_internal')
165
  st.markdown("---")
166
- st.write("HISTORY")
167
  if st.session_state.history:
168
  for h in reversed(st.session_state.history):
169
  st.markdown(f"<div style='font-size:0.8rem; padding:5px; border-left:2px solid #38bdf8; margin-bottom:5px;'>{h[:50]}...</div>", unsafe_allow_html=True)
170
  else:
171
- st.caption("No scans yet.")
172
  st.markdown("---")
173
  if st.button("Sign Out"): sign_out()
174
 
175
- st.title(f"{MODEL_ID.title()} Interface")
176
- t1, t2 = st.tabs(["📷 Image Scan", "📝 Text Analysis"])
177
 
178
  with t1:
179
  st.markdown("<div class='shinui-card'>", unsafe_allow_html=True)
180
- img_file = st.file_uploader("Upload Image", type=['png','jpg','jpeg'])
181
- if img_file and st.button("Analyze Visual"):
182
  image = Image.open(img_file)
183
  st.image(image, width=300)
184
- with st.spinner(f"{MODEL_ID} Processing..."):
185
  res = get_insight("Image", image)
186
  st.session_state.result = res
187
- st.session_state.history.append(f"Image: {res[:30]}...")
188
  st.markdown("</div>", unsafe_allow_html=True)
189
 
190
  with t2:
191
  st.markdown("<div class='shinui-card'>", unsafe_allow_html=True)
192
- txt = st.text_area("Clinical Notes")
193
- if txt and st.button("Analyze Notes"):
194
- with st.spinner(f"{MODEL_ID} Processing..."):
195
  res = get_insight("Text", txt)
196
  st.session_state.result = res
197
- st.session_state.history.append(f"Text: {res[:30]}...")
198
  st.markdown("</div>", unsafe_allow_html=True)
199
 
200
  if st.session_state.result:
201
  st.markdown(f"""
202
  <div class='shinui-card' style='border-left: 5px solid #38bdf8;'>
203
- <h3 style='margin-top:0; color:#38bdf8;'>Analysis Result</h3>
204
  <div style='white-space: pre-wrap; color: #e2e8f0; line-height: 1.6;'>{st.session_state.result}</div>
205
  </div>
206
  """, unsafe_allow_html=True)
@@ -212,7 +218,8 @@ def show_about_internal():
212
  st.markdown(f"""
213
  <div class='shinui-card'>
214
  <h2 style='color:#38bdf8'>System Status</h2>
215
- <p><b>Model:</b> {MODEL_ID}</p>
 
216
  <p><b>Status:</b> Online</p>
217
  </div>
218
  """, unsafe_allow_html=True)
@@ -228,4 +235,5 @@ elif st.session_state.page == 'dashboard':
228
  else: nav_to('login')
229
  elif st.session_state.page == 'about_internal':
230
  if st.session_state.logged_in: show_about_internal()
231
- else: nav_to('login')
 
 
1
  import streamlit as st
2
  import os
3
+ import google.generativeai as genai # <--- Fixed import for your environment
 
4
  from PIL import Image
5
 
6
  # -----------------------------------------------------------------------------
 
13
  f.write("[server]\nenableXsrfProtection=false\nenableCORS=false\nmaxUploadSize=200\n")
14
 
15
  # -----------------------------------------------------------------------------
16
+ # 1. SETUP & GOOGLE API
17
  # -----------------------------------------------------------------------------
18
  st.set_page_config(page_title="Shinui | Medical AI", page_icon="✨", layout="wide")
19
 
 
22
  st.error("⚠️ Google API Key Missing in Secrets.")
23
  st.stop()
24
 
25
+ # Configure the standard library
26
+ genai.configure(api_key=GOOGLE_API_KEY)
27
 
28
+ # -----------------------------------------------------------------------------
29
+ # ⚠️ MODEL CONFIGURATION
30
+ # -----------------------------------------------------------------------------
31
+ MODEL_ID = "gemini-2.5-pro"
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
 
43
  # 3. LOGIC
44
  # -----------------------------------------------------------------------------
45
  def get_insight(input_type, content):
46
+ system_instruction = (
47
+ "You are Shinui, an advanced medical AI assistant. "
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
  try:
54
+ # Initialize the specific model requested
55
+ model = genai.GenerativeModel(MODEL_ID)
56
+
57
  if input_type == "Image":
58
+ # The standard SDK handles [text, image] lists natively
59
+ response = model.generate_content([system_instruction, content])
 
 
 
60
  return response.text
61
 
62
  elif input_type == "Text":
63
+ full_prompt = f"{system_instruction}\n\nPatient Notes/Input: {content}"
64
+ response = model.generate_content(full_prompt)
 
 
 
65
  return response.text
66
 
67
  except Exception as e:
68
+ return f"System Error ({MODEL_ID}): {str(e)}"
69
 
70
  def nav_to(page):
71
  st.session_state.page = page
 
87
  .stApp { background-color: #020617; font-family: 'Plus Jakarta Sans', sans-serif; color: #f8fafc; }
88
  .shinui-card { background: rgba(30, 41, 59, 0.4); border: 1px solid rgba(148, 163, 184, 0.1); border-radius: 16px; padding: 25px; margin-bottom: 20px; }
89
  div.stButton > button { background: #38bdf8; color: #0f172a; border: none; font-weight: 700; padding: 12px 20px; border-radius: 8px; width: 100%; }
90
+ h1, h2, h3 { letter-spacing: -0.02em; }
91
  #MainMenu, footer, header {visibility: hidden;}
92
  </style>
93
  """, unsafe_allow_html=True)
 
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
 
 
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)
 
167
  def show_dashboard():
168
  with st.sidebar:
169
  st.markdown(f"### 👤 {st.session_state.user_email}")
170
+ if st.button("System Status"): nav_to('about_internal')
171
  st.markdown("---")
172
+ st.write("SESSION HISTORY")
173
  if st.session_state.history:
174
  for h in reversed(st.session_state.history):
175
  st.markdown(f"<div style='font-size:0.8rem; padding:5px; border-left:2px solid #38bdf8; margin-bottom:5px;'>{h[:50]}...</div>", unsafe_allow_html=True)
176
  else:
177
+ st.caption("No analysis performed yet.")
178
  st.markdown("---")
179
  if st.button("Sign Out"): sign_out()
180
 
181
+ st.title(f"Shinui Interface ({MODEL_ID})")
182
+ t1, t2 = st.tabs(["📷 Advanced Image Scan", "📝 Clinical Text Analysis"])
183
 
184
  with t1:
185
  st.markdown("<div class='shinui-card'>", unsafe_allow_html=True)
186
+ img_file = st.file_uploader("Upload Medical Imaging", type=['png','jpg','jpeg'])
187
+ if img_file and st.button("Run 2.5 Pro Analysis"):
188
  image = Image.open(img_file)
189
  st.image(image, width=300)
190
+ with st.spinner(f"Running deep analysis with {MODEL_ID}..."):
191
  res = get_insight("Image", image)
192
  st.session_state.result = res
193
+ st.session_state.history.append(f"Img: {res[:30]}...")
194
  st.markdown("</div>", unsafe_allow_html=True)
195
 
196
  with t2:
197
  st.markdown("<div class='shinui-card'>", unsafe_allow_html=True)
198
+ txt = st.text_area("Clinical Notes / Symptoms")
199
+ if txt and st.button("Run 2.5 Pro Analysis"):
200
+ with st.spinner(f"Running deep analysis with {MODEL_ID}..."):
201
  res = get_insight("Text", txt)
202
  st.session_state.result = res
203
+ st.session_state.history.append(f"Txt: {res[:30]}...")
204
  st.markdown("</div>", unsafe_allow_html=True)
205
 
206
  if st.session_state.result:
207
  st.markdown(f"""
208
  <div class='shinui-card' style='border-left: 5px solid #38bdf8;'>
209
+ <h3 style='margin-top:0; color:#38bdf8;'>Analysis Result ({MODEL_ID})</h3>
210
  <div style='white-space: pre-wrap; color: #e2e8f0; line-height: 1.6;'>{st.session_state.result}</div>
211
  </div>
212
  """, unsafe_allow_html=True)
 
218
  st.markdown(f"""
219
  <div class='shinui-card'>
220
  <h2 style='color:#38bdf8'>System Status</h2>
221
+ <p><b>Active Model:</b> {MODEL_ID}</p>
222
+ <p><b>Library:</b> google-generativeai (Standard)</p>
223
  <p><b>Status:</b> Online</p>
224
  </div>
225
  """, unsafe_allow_html=True)
 
235
  else: nav_to('login')
236
  elif st.session_state.page == 'about_internal':
237
  if st.session_state.logged_in: show_about_internal()
238
+ else: nav_to('login')
239
+