mgbam commited on
Commit
a3ddee2
·
verified ·
1 Parent(s): a90f7d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -7,7 +7,7 @@ import logging
7
  from dotenv import load_dotenv
8
 
9
  # Configure logging
10
- tlogging = logging.getLogger(__name__)
11
  logging.basicConfig(level=logging.INFO)
12
 
13
  # Import agent logic and message types
@@ -15,7 +15,7 @@ try:
15
  from agent import ClinicalAgent, AgentState, check_red_flags
16
  from langchain_core.messages import HumanMessage, AIMessage, ToolMessage
17
  except ImportError as e:
18
- logging.exception("Failed to import from agent.py")
19
  st.error(f"Failed to import from agent.py: {e}. Make sure agent.py is in the same directory.")
20
  st.stop()
21
 
@@ -39,7 +39,7 @@ def get_agent():
39
  try:
40
  return ClinicalAgent()
41
  except Exception as e:
42
- logging.exception("Failed to initialize ClinicalAgent")
43
  st.error(f"Failed to initialize Clinical Agent: {e}. Check API keys and dependencies.")
44
  st.stop()
45
 
@@ -86,7 +86,9 @@ def load_patient_intake():
86
  bp_mmhg = st.text_input("BP", "155/90", key="sb_bp")
87
  spo2_percent = st.number_input("SpO2", min_value=70, max_value=100, value=96, key="sb_spo2")
88
  pain_scale = st.slider("Pain", min_value=0, max_value=10, value=8, key="sb_pain")
89
- exam_notes = st.text_area("Exam Notes", "Awake, alert...", height=50, key="sb_exam")
 
 
90
 
91
  # Process meds and allergies with comprehensions
92
  current_meds_list = [m.strip() for m in current_meds_str.splitlines() if m.strip()]
@@ -107,7 +109,7 @@ def load_patient_intake():
107
  try:
108
  bp_sys, bp_dia = map(int, bp_mmhg.split("/"))
109
  except ValueError:
110
- logging.warning(f"Unable to parse BP '{bp_mmhg}'")
111
 
112
  return {
113
  "demographics": {"age": age, "sex": sex},
@@ -132,7 +134,6 @@ def load_patient_intake():
132
  }
133
 
134
  # Main application
135
-
136
  def main():
137
  st.set_page_config(page_title=ClinicalAppSettings.APP_TITLE, layout=ClinicalAppSettings.PAGE_LAYOUT)
138
  st.title(f"🩺 {ClinicalAppSettings.APP_TITLE}")
@@ -190,7 +191,7 @@ def main():
190
  else:
191
  st.markdown(ai_content)
192
  except (AttributeError, json.JSONDecodeError) as e:
193
- logging.warning(f"JSON parse error: {e}")
194
  st.markdown(ai_content)
195
 
196
  if structured_output and isinstance(structured_output, dict):
@@ -199,7 +200,7 @@ def main():
199
  cols = st.columns(2)
200
  with cols[0]:
201
  st.markdown("**Assessment:**")
202
- st.markdown(f"> {structured_output.get('assessment', 'N/A')}" )
203
  st.markdown("**Differential Diagnosis:**")
204
  ddx = structured_output.get('differential_diagnosis', [])
205
  if ddx:
@@ -235,7 +236,7 @@ def main():
235
  st.markdown("_None_")
236
 
237
  st.markdown("**Rationale & Guideline Check:**")
238
- st.markdown(f"> {structured_output.get('rationale_summary', 'N/A')}" )
239
  if interaction := structured_output.get('interaction_check_summary'):
240
  st.markdown("**Interaction Check Summary:**")
241
  st.markdown(f"> {interaction}")
@@ -282,7 +283,7 @@ def main():
282
  st.session_state.messages = final_state.get('messages', [])
283
  st.session_state.summary = final_state.get('summary')
284
  except Exception as e:
285
- logging.exception("Error during agent.invoke_turn")
286
  st.error(f"Error: {e}")
287
  st.session_state.messages.append(AIMessage(content=f"Error processing request: {e}"))
288
  st.rerun()
@@ -292,4 +293,4 @@ def main():
292
  st.warning("**Disclaimer:** SynapseAI is for demonstration only and not for clinical use.")
293
 
294
  if __name__ == "__main__":
295
- main()
 
7
  from dotenv import load_dotenv
8
 
9
  # Configure logging
10
+ logger = logging.getLogger(__name__)
11
  logging.basicConfig(level=logging.INFO)
12
 
13
  # Import agent logic and message types
 
15
  from agent import ClinicalAgent, AgentState, check_red_flags
16
  from langchain_core.messages import HumanMessage, AIMessage, ToolMessage
17
  except ImportError as e:
18
+ logger.exception("Failed to import from agent.py")
19
  st.error(f"Failed to import from agent.py: {e}. Make sure agent.py is in the same directory.")
20
  st.stop()
21
 
 
39
  try:
40
  return ClinicalAgent()
41
  except Exception as e:
42
+ logger.exception("Failed to initialize ClinicalAgent")
43
  st.error(f"Failed to initialize Clinical Agent: {e}. Check API keys and dependencies.")
44
  st.stop()
45
 
 
86
  bp_mmhg = st.text_input("BP", "155/90", key="sb_bp")
87
  spo2_percent = st.number_input("SpO2", min_value=70, max_value=100, value=96, key="sb_spo2")
88
  pain_scale = st.slider("Pain", min_value=0, max_value=10, value=8, key="sb_pain")
89
+
90
+ # Updated minimum height to 68px to satisfy Streamlit requirement
91
+ exam_notes = st.text_area("Exam Notes", "Awake, alert...", height=68, key="sb_exam")
92
 
93
  # Process meds and allergies with comprehensions
94
  current_meds_list = [m.strip() for m in current_meds_str.splitlines() if m.strip()]
 
109
  try:
110
  bp_sys, bp_dia = map(int, bp_mmhg.split("/"))
111
  except ValueError:
112
+ logger.warning(f"Unable to parse BP '{bp_mmhg}'")
113
 
114
  return {
115
  "demographics": {"age": age, "sex": sex},
 
134
  }
135
 
136
  # Main application
 
137
  def main():
138
  st.set_page_config(page_title=ClinicalAppSettings.APP_TITLE, layout=ClinicalAppSettings.PAGE_LAYOUT)
139
  st.title(f"🩺 {ClinicalAppSettings.APP_TITLE}")
 
191
  else:
192
  st.markdown(ai_content)
193
  except (AttributeError, json.JSONDecodeError) as e:
194
+ logger.warning(f"JSON parse error: {e}")
195
  st.markdown(ai_content)
196
 
197
  if structured_output and isinstance(structured_output, dict):
 
200
  cols = st.columns(2)
201
  with cols[0]:
202
  st.markdown("**Assessment:**")
203
+ st.markdown(f"> {structured_output.get('assessment', 'N/A')}")
204
  st.markdown("**Differential Diagnosis:**")
205
  ddx = structured_output.get('differential_diagnosis', [])
206
  if ddx:
 
236
  st.markdown("_None_")
237
 
238
  st.markdown("**Rationale & Guideline Check:**")
239
+ st.markdown(f"> {structured_output.get('rationale_summary', 'N/A')}")
240
  if interaction := structured_output.get('interaction_check_summary'):
241
  st.markdown("**Interaction Check Summary:**")
242
  st.markdown(f"> {interaction}")
 
283
  st.session_state.messages = final_state.get('messages', [])
284
  st.session_state.summary = final_state.get('summary')
285
  except Exception as e:
286
+ logger.exception("Error during agent.invoke_turn")
287
  st.error(f"Error: {e}")
288
  st.session_state.messages.append(AIMessage(content=f"Error processing request: {e}"))
289
  st.rerun()
 
293
  st.warning("**Disclaimer:** SynapseAI is for demonstration only and not for clinical use.")
294
 
295
  if __name__ == "__main__":
296
+ main()