naman1102 commited on
Commit
f18f370
·
1 Parent(s): afe6455

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -257,19 +257,28 @@ class BasicAgent:
257
  "logs": {},
258
  "file_url": file_url,
259
  "code_blocks": [],
260
- "next_step": "" # Initialize next_step
261
  }
262
 
263
  print(f"\nProcessing task {task_id}")
264
  print(f"Question: {state['question']}")
265
  print(f"File URL: {state['file_url']}")
266
 
267
- final_state = self.workflow.invoke(state)
268
- return final_state["final_answer"]
 
 
 
 
 
 
 
 
269
 
270
  def _route_to_tool(self, state: AgentState) -> Dict[str, Any]:
271
  """Route the state to the appropriate tool based on file type."""
272
  if not state["file_url"]:
 
273
  return {"next_step": "process_text"}
274
 
275
  try:
@@ -291,6 +300,8 @@ class BasicAgent:
291
  elif not kind: # fallback if header missing
292
  kind = mimetypes.guess_type(state["file_url"])[0] or ""
293
 
 
 
294
  if "image" in kind:
295
  return {"next_step": "process_image"}
296
  elif "video" in kind:
 
257
  "logs": {},
258
  "file_url": file_url,
259
  "code_blocks": [],
260
+ "next_step": ""
261
  }
262
 
263
  print(f"\nProcessing task {task_id}")
264
  print(f"Question: {state['question']}")
265
  print(f"File URL: {state['file_url']}")
266
 
267
+ try:
268
+ final_state = self.workflow.invoke(state)
269
+ answer = final_state.get("final_answer", "")
270
+ if not answer:
271
+ print("Warning: No answer generated in final state")
272
+ return "No answer could be generated"
273
+ return answer
274
+ except Exception as e:
275
+ print(f"Error in workflow execution: {str(e)}")
276
+ return f"Error processing question: {str(e)}"
277
 
278
  def _route_to_tool(self, state: AgentState) -> Dict[str, Any]:
279
  """Route the state to the appropriate tool based on file type."""
280
  if not state["file_url"]:
281
+ print("No file URL, routing to text processing")
282
  return {"next_step": "process_text"}
283
 
284
  try:
 
300
  elif not kind: # fallback if header missing
301
  kind = mimetypes.guess_type(state["file_url"])[0] or ""
302
 
303
+ print(f"Detected file type: {kind}")
304
+
305
  if "image" in kind:
306
  return {"next_step": "process_image"}
307
  elif "video" in kind: