DiogoPinheiro commited on
Commit
437f85b
·
1 Parent(s): 57d0505

fix: rollback

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -3,26 +3,36 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
6
- from FinalAssignmentAgent import FinalAssignmentAgent
7
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
 
 
 
 
 
 
 
 
 
 
 
12
  def run_and_submit_all( profile: gr.OAuthProfile | None):
13
  """
14
- Fetches all questions, runs the FinalAssignmentAgent on them, submits all answers,
15
  and displays the results.
16
  """
17
  # --- Determine HF Space Runtime URL and Repo URL ---
18
- space_id = os.getenv("SPACE_ID")
19
 
20
  if profile:
21
  username= f"{profile.username}"
22
  print(f"User logged in: {username}")
23
  else:
24
  print("User not logged in.")
25
- # return "Please Login to Hugging Face with the button.", None
26
 
27
  api_url = DEFAULT_API_URL
28
  questions_url = f"{api_url}/questions"
@@ -30,7 +40,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
30
 
31
  # 1. Instantiate Agent ( modify this part to create your agent)
32
  try:
33
- agent = FinalAssignmentAgent()
34
  except Exception as e:
35
  print(f"Error instantiating agent: {e}")
36
  return f"Error initializing agent: {e}", None
@@ -86,8 +96,6 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
86
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
87
  print(status_update)
88
 
89
- print(answers_payload)
90
-
91
  # 5. Submit
92
  print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
93
  try:
@@ -134,16 +142,13 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
134
 
135
  # --- Build Gradio Interface using Blocks ---
136
  with gr.Blocks() as demo:
137
-
138
  gr.Markdown("# Basic Agent Evaluation Runner")
139
  gr.Markdown(
140
  """
141
  **Instructions:**
142
-
143
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
144
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
145
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
146
-
147
  ---
148
  **Disclaimers:**
149
  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).
@@ -166,8 +171,9 @@ with gr.Blocks() as demo:
166
 
167
  if __name__ == "__main__":
168
  print("\n" + "-"*30 + " App Starting " + "-"*30)
 
169
  space_host_startup = os.getenv("SPACE_HOST")
170
- space_id_startup = os.getenv("SPACE_ID")
171
 
172
  if space_host_startup:
173
  print(f"✅ SPACE_HOST found: {space_host_startup}")
 
3
  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"
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
  """
24
+ Fetches all questions, runs the BasicAgent on them, submits all answers,
25
  and displays the results.
26
  """
27
  # --- Determine HF Space Runtime URL and Repo URL ---
28
+ space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
29
 
30
  if profile:
31
  username= f"{profile.username}"
32
  print(f"User logged in: {username}")
33
  else:
34
  print("User not logged in.")
35
+ return "Please Login to Hugging Face with the button.", None
36
 
37
  api_url = DEFAULT_API_URL
38
  questions_url = f"{api_url}/questions"
 
40
 
41
  # 1. Instantiate Agent ( modify this part to create your agent)
42
  try:
43
+ agent = BasicAgent()
44
  except Exception as e:
45
  print(f"Error instantiating agent: {e}")
46
  return f"Error initializing agent: {e}", None
 
96
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
97
  print(status_update)
98
 
 
 
99
  # 5. Submit
100
  print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
101
  try:
 
142
 
143
  # --- Build Gradio Interface using Blocks ---
144
  with gr.Blocks() as demo:
 
145
  gr.Markdown("# Basic Agent Evaluation Runner")
146
  gr.Markdown(
147
  """
148
  **Instructions:**
 
149
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
150
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
151
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
 
152
  ---
153
  **Disclaimers:**
154
  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).
 
171
 
172
  if __name__ == "__main__":
173
  print("\n" + "-"*30 + " App Starting " + "-"*30)
174
+ # Check for SPACE_HOST and SPACE_ID at startup for information
175
  space_host_startup = os.getenv("SPACE_HOST")
176
+ space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
177
 
178
  if space_host_startup:
179
  print(f"✅ SPACE_HOST found: {space_host_startup}")