AksharaSachin commited on
Commit
a98c0d0
·
verified ·
1 Parent(s): d82cdbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -12,14 +12,19 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
  # --- Basic Agent Definition ---
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
- # class BasicAgent:
16
- # def __init__(self):
17
- # print("BasicAgent initialized.")
18
- # def __call__(self, question: str) -> str:
19
- # print(f"Agent received question (first 50 chars): {question[:50]}...")
20
- # fixed_answer = "This is a default answer."
21
- # print(f"Agent returning fixed answer: {fixed_answer}")
22
- # return fixed_answer
 
 
 
 
 
23
 
24
  def run_and_submit_all( profile: gr.OAuthProfile | None):
25
  """
@@ -42,8 +47,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
42
 
43
  # 1. Instantiate Agent ( modify this part to create your agent)
44
  try:
45
- #agent = BasicAgent()
46
- agent = build_agent()
47
  except Exception as e:
48
  print(f"Error instantiating agent: {e}")
49
  return f"Error initializing agent: {e}", None
@@ -83,10 +87,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
83
  print(f"Skipping item with missing task_id or question: {item}")
84
  continue
85
  try:
86
- input = HumanMessage(content=question_text)
87
- response = agent.invoke({"messages" :input})
88
- submitted_answer = response["messages"][-1].content
89
- #submitted_answer = agent(question_text)
90
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
91
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
92
  except Exception as e:
 
12
 
13
  # --- Basic Agent Definition ---
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
+ class BasicAgent:
16
+ """A langgraph agent."""
17
+ def __init__(self):
18
+ print("BasicAgent initialized.")
19
+ self.graph = build_agent()
20
+
21
+ def __call__(self, question: str) -> str:
22
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
23
+ # Wrap the question in a HumanMessage from langchain_core
24
+ messages = [HumanMessage(content=question)]
25
+ messages = self.graph.invoke({"messages": messages})
26
+ answer = messages['messages'][-1].content
27
+ return answer[14:]
28
 
29
  def run_and_submit_all( profile: gr.OAuthProfile | None):
30
  """
 
47
 
48
  # 1. Instantiate Agent ( modify this part to create your agent)
49
  try:
50
+ agent = BasicAgent()
 
51
  except Exception as e:
52
  print(f"Error instantiating agent: {e}")
53
  return f"Error initializing agent: {e}", None
 
87
  print(f"Skipping item with missing task_id or question: {item}")
88
  continue
89
  try:
90
+ submitted_answer = agent(question_text)
 
 
 
91
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
92
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
93
  except Exception as e: