naman1102 commited on
Commit
cc0b0be
·
1 Parent(s): fc6f881

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -8
app.py CHANGED
@@ -30,8 +30,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
30
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
31
  JINA_API_KEY = os.getenv("JINA_API_KEY")
32
 
33
- LOGS_DIR = "question_logs"
34
- os.makedirs(LOGS_DIR, exist_ok=True)
35
 
36
  # -------------------------
37
  # Jina AI search tool (replaces DDG + Reader)
@@ -183,8 +182,6 @@ class BasicAgent:
183
  "logs": {},
184
  }
185
  final_state = self.workflow.invoke(state)
186
- if final_state["logs"]:
187
- log_to_file(task_id, question, final_state["logs"])
188
  return final_state["final_answer"]
189
 
190
  # ----------------------------------------------------------------------------------
@@ -258,14 +255,33 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
258
 
259
  try:
260
  print(f"\nProcessing question {task_id}: {question_text[:50]}...")
261
- answer = agent(question_text, task_id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
 
263
  # Add to results
264
  answers_payload.append({"task_id": task_id, "submitted_answer": answer})
265
  results_log.append({
266
  "Task ID": task_id,
267
  "Question": question_text,
268
- "Submitted Answer": answer
 
269
  })
270
 
271
  print(f"Completed question {task_id}")
@@ -275,7 +291,8 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
275
  results_log.append({
276
  "Task ID": task_id,
277
  "Question": question_text,
278
- "Submitted Answer": f"ERROR: {e}"
 
279
  })
280
 
281
  if not answers_payload:
@@ -358,7 +375,11 @@ with gr.Blocks() as demo:
358
  run_button = gr.Button("Run Evaluation & Submit All Answers")
359
 
360
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
361
- results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
 
 
 
 
362
 
363
  run_button.click(
364
  fn=run_and_submit_all,
 
30
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
31
  JINA_API_KEY = os.getenv("JINA_API_KEY")
32
 
33
+ # Remove logs directory creation since we're not storing logs anymore
 
34
 
35
  # -------------------------
36
  # Jina AI search tool (replaces DDG + Reader)
 
182
  "logs": {},
183
  }
184
  final_state = self.workflow.invoke(state)
 
 
185
  return final_state["final_answer"]
186
 
187
  # ----------------------------------------------------------------------------------
 
255
 
256
  try:
257
  print(f"\nProcessing question {task_id}: {question_text[:50]}...")
258
+
259
+ # Initialize state for this question
260
+ state: AgentState = {
261
+ "question": question_text,
262
+ "current_step": "analyze",
263
+ "final_answer": "",
264
+ "history": [],
265
+ "needs_search": False,
266
+ "search_query": "",
267
+ "task_id": task_id,
268
+ "logs": {},
269
+ }
270
+
271
+ # Run the workflow
272
+ final_state = agent.workflow.invoke(state)
273
+ answer = final_state["final_answer"]
274
+
275
+ # Format logs for display
276
+ logs_text = json.dumps(final_state["logs"], indent=2)
277
 
278
  # Add to results
279
  answers_payload.append({"task_id": task_id, "submitted_answer": answer})
280
  results_log.append({
281
  "Task ID": task_id,
282
  "Question": question_text,
283
+ "Submitted Answer": answer,
284
+ "Processing Logs": logs_text
285
  })
286
 
287
  print(f"Completed question {task_id}")
 
291
  results_log.append({
292
  "Task ID": task_id,
293
  "Question": question_text,
294
+ "Submitted Answer": f"ERROR: {e}",
295
+ "Processing Logs": f"Error occurred: {str(e)}"
296
  })
297
 
298
  if not answers_payload:
 
375
  run_button = gr.Button("Run Evaluation & Submit All Answers")
376
 
377
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
378
+ results_table = gr.DataFrame(
379
+ label="Questions and Agent Answers",
380
+ wrap=True,
381
+ column_widths=["10%", "30%", "30%", "30%"] # Adjust column widths for better display
382
+ )
383
 
384
  run_button.click(
385
  fn=run_and_submit_all,