lisaterumi commited on
Commit
22c2471
·
verified ·
1 Parent(s): b6fb167

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -4,6 +4,9 @@ import requests
4
  import inspect
5
  import pandas as pd
6
 
 
 
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -13,11 +16,19 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
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
  """
@@ -146,11 +157,9 @@ with gr.Blocks() as demo:
146
  gr.Markdown(
147
  """
148
  **Instructions:**
149
-
150
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
151
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
152
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
153
-
154
  ---
155
  **Disclaimers:**
156
  Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ from langchain_core.messages import HumanMessage
8
+ from agent import build_graph
9
+
10
  # (Keep Constants as is)
11
  # --- Constants ---
12
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
16
  class BasicAgent:
17
  def __init__(self):
18
  print("BasicAgent initialized.")
19
+ self.graph = build_graph()
20
+
21
  def __call__(self, question: str) -> str:
22
  print(f"Agent received question (first 50 chars): {question[:50]}...")
23
+
24
+ messages = [HumanMessage(content=question)]
25
+ result = self.graph.invoke({"messages": messages})
26
+ answer = result['messages'][-1].content
27
+ return answer # kein [14:] mehr nötig!
28
+
29
+ # fixed_answer = "This is a default answer."
30
+ # print(f"Agent returning fixed answer: {fixed_answer}")
31
+ # return fixed_answer
32
 
33
  def run_and_submit_all( profile: gr.OAuthProfile | None):
34
  """
 
157
  gr.Markdown(
158
  """
159
  **Instructions:**
 
160
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
161
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
162
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
 
163
  ---
164
  **Disclaimers:**
165
  Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).