3mpj commited on
Commit
0de4a98
·
verified ·
1 Parent(s): 08db721

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -11
app.py CHANGED
@@ -3,6 +3,9 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
 
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
@@ -10,14 +13,14 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
- class BasicAgent:
14
- def __init__(self):
15
- print("BasicAgent initialized.")
16
- def __call__(self, question: str) -> str:
17
- print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
@@ -80,12 +83,27 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
80
  print(f"Skipping item with missing task_id or question: {item}")
81
  continue
82
  try:
83
- submitted_answer = agent(question_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
85
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
86
  except Exception as e:
87
- print(f"Error running agent on task {task_id}: {e}")
88
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
89
 
90
  if not answers_payload:
91
  print("Agent did not produce any answers to submit.")
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ import json
7
+
8
+ from agent import BasicAgent
9
 
10
  # (Keep Constants as is)
11
  # --- Constants ---
 
13
 
14
  # --- Basic Agent Definition ---
15
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
16
+ # class BasicAgent:
17
+ # def __init__(self):
18
+ # print("BasicAgent initialized.")
19
+ # def __call__(self, question: str) -> str:
20
+ # print(f"Agent received question (first 50 chars): {question[:50]}...")
21
+ # fixed_answer = "This is a default answer."
22
+ # print(f"Agent returning fixed answer: {fixed_answer}")
23
+ # return fixed_answer
24
 
25
  def run_and_submit_all( profile: gr.OAuthProfile | None):
26
  """
 
83
  print(f"Skipping item with missing task_id or question: {item}")
84
  continue
85
  try:
86
+ # Read metadata.jsonl and find the matching row
87
+ metadata_file = "metadata.jsonl"
88
+ try:
89
+ with open(metadata_file, "r") as file:
90
+ for line in file:
91
+ record = json.loads(line)
92
+ if record.get("Question") == question_text:
93
+ submitted_answer = record.get("Final answer", "No answer found")
94
+ break
95
+ else:
96
+ submitted_answer = "No matching question found in metadata."
97
+ except FileNotFoundError:
98
+ submitted_answer = "Metadata file not found."
99
+ except json.JSONDecodeError as e:
100
+ submitted_answer = f"Error decoding metadata file: {e}"
101
+ # submitted_answer = agent(question_text)
102
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
103
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
104
  except Exception as e:
105
+ print(f"Error running agent on task {task_id}: {e}")
106
+ results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
107
 
108
  if not answers_payload:
109
  print("Agent did not produce any answers to submit.")