antonioschiro commited on
Commit
4d431e0
·
verified ·
1 Parent(s): 2171e7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -22,10 +22,11 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
22
  class BasicAgent:
23
  def __init__(self):
24
  self.agent = alfred
25
- def __call__(self, question: str) -> str:
26
- state_dict = alfred.invoke({"messages": [HumanMessage(content = question)]})
27
  response = state_dict["messages"][-1]
28
  try:
 
29
  response = response.content
30
  matches = re.findall(r"Final Answer:\s*(.*)", response)
31
  if matches:
@@ -34,7 +35,7 @@ class BasicAgent:
34
  except:
35
  return "Sorry, I can't answer to this question."
36
 
37
- def run_and_submit_all( profile: gr.OAuthProfile | None):
38
  """
39
  Fetches all questions, runs the BasicAgent on them, submits all answers,
40
  and displays the results.
@@ -55,7 +56,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
55
 
56
  # 1. Instantiate Agent ( modify this part to create your agent)
57
  try:
58
- agent = BasicAgent()
59
  except Exception as e:
60
  print(f"Error instantiating agent: {e}")
61
  return f"Error initializing agent: {e}", None
@@ -95,7 +96,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
95
  print(f"Skipping item with missing task_id or question: {item}")
96
  continue
97
  try:
98
- submitted_answer = agent(question_text)
99
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
100
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
101
  except Exception as e:
 
22
  class BasicAgent:
23
  def __init__(self):
24
  self.agent = alfred
25
+ async def __call__(self, question: str) -> str:
26
+ state_dict = await alfred.ainvoke({"messages": [HumanMessage(content = question)]})
27
  response = state_dict["messages"][-1]
28
  try:
29
+ print(response)
30
  response = response.content
31
  matches = re.findall(r"Final Answer:\s*(.*)", response)
32
  if matches:
 
35
  except:
36
  return "Sorry, I can't answer to this question."
37
 
38
+ async def run_and_submit_all( profile: gr.OAuthProfile | None):
39
  """
40
  Fetches all questions, runs the BasicAgent on them, submits all answers,
41
  and displays the results.
 
56
 
57
  # 1. Instantiate Agent ( modify this part to create your agent)
58
  try:
59
+ agent = await BasicAgent()
60
  except Exception as e:
61
  print(f"Error instantiating agent: {e}")
62
  return f"Error initializing agent: {e}", None
 
96
  print(f"Skipping item with missing task_id or question: {item}")
97
  continue
98
  try:
99
+ submitted_answer = await agent(question_text)
100
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
101
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
102
  except Exception as e: