cryogenic22 commited on
Commit
f85e2e6
·
verified ·
1 Parent(s): 18580d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -15
app.py CHANGED
@@ -175,19 +175,28 @@ if "initialization_attempted" not in st.session_state:
175
  # Run workflow in separate thread
176
  def run_workflow_thread(workflow, alert):
177
  try:
178
- # Log start of workflow
179
  logger.info(f"Starting workflow for alert: {alert}")
 
 
 
 
 
 
180
 
181
  # Update status
182
- st.session_state.status_queue.put(("info", "Planning analysis approach..."))
183
- st.session_state.current_step = "planning"
 
 
 
184
 
185
- # Run the workflow with more detailed logging
186
- logger.info("Invoking workflow run...")
187
  result = workflow.run_workflow(alert)
188
 
189
- # Log completion
190
- logger.info("Workflow completed successfully")
191
 
192
  # Store the result
193
  st.session_state.workflow_state = result
@@ -195,22 +204,33 @@ def run_workflow_thread(workflow, alert):
195
  # Update status
196
  st.session_state.status_queue.put(("success", "Analysis complete!"))
197
  st.session_state.current_step = "complete"
 
 
 
198
  except Exception as e:
199
- # Capture the full stack trace
200
- stack_trace = traceback.format_exc()
201
- error_msg = f"Error: {str(e)}\n\nStack trace:\n{stack_trace}"
 
 
 
 
202
 
203
- # Log the error
204
- logger.error(error_msg)
 
205
 
206
- # Update status with more details
207
- st.session_state.status_queue.put(("error", f"Error: {str(e)}"))
 
 
 
208
  st.session_state.current_step = "error"
209
 
210
  # Store error details for debugging
211
  if "error_details" not in st.session_state:
212
  st.session_state.error_details = []
213
- st.session_state.error_details.append(error_msg)
214
 
215
  # Main application header
216
  st.title("🔮 Agentic Pharmaceutical Analytics Platform")
 
175
  # Run workflow in separate thread
176
  def run_workflow_thread(workflow, alert):
177
  try:
178
+ # Log start of workflow with more details
179
  logger.info(f"Starting workflow for alert: {alert}")
180
+ logger.info(f"Workflow object: {workflow}")
181
+ logger.info(f"Alert type: {type(alert)}")
182
+
183
+ # Validate inputs
184
+ if not alert or not isinstance(alert, str):
185
+ raise ValueError("Invalid alert: Must be a non-empty string")
186
 
187
  # Update status
188
+ st.session_state.status_queue.put(("info", "Initializing workflow..."))
189
+ st.session_state.current_step = "initializing"
190
+
191
+ # Log agent and workflow details
192
+ logger.info("Workflow initialization started")
193
 
194
+ # Run the workflow
195
+ logger.info("Invoking workflow run method")
196
  result = workflow.run_workflow(alert)
197
 
198
+ # Log workflow result details
199
+ logger.info(f"Workflow completed. Status: {result.get('status', 'Unknown')}")
200
 
201
  # Store the result
202
  st.session_state.workflow_state = result
 
204
  # Update status
205
  st.session_state.status_queue.put(("success", "Analysis complete!"))
206
  st.session_state.current_step = "complete"
207
+
208
+ logger.info("Workflow thread completed successfully")
209
+
210
  except Exception as e:
211
+ # Capture detailed error information
212
+ error_details = {
213
+ "error_message": str(e),
214
+ "traceback": traceback.format_exc(),
215
+ "alert": alert,
216
+ "workflow_object": str(workflow)
217
+ }
218
 
219
+ # Log the error comprehensively
220
+ logger.error("Workflow thread failed")
221
+ logger.error(f"Error details: {json.dumps(error_details, indent=2)}")
222
 
223
+ # Update error state
224
+ st.session_state.status_queue.put((
225
+ "error",
226
+ f"Workflow Execution Error: {str(e)}"
227
+ ))
228
  st.session_state.current_step = "error"
229
 
230
  # Store error details for debugging
231
  if "error_details" not in st.session_state:
232
  st.session_state.error_details = []
233
+ st.session_state.error_details.append(error_details)
234
 
235
  # Main application header
236
  st.title("🔮 Agentic Pharmaceutical Analytics Platform")