shalanova commited on
Commit
7f84da0
·
verified ·
1 Parent(s): 3a47c54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -1,24 +1,16 @@
1
  import os
 
2
  import gradio as gr
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,
@@ -51,9 +43,16 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
51
  # 2. Fetch Questions
52
  print(f"Fetching questions from: {questions_url}")
53
  try:
54
- response = requests.get(questions_url, timeout=15)
55
- response.raise_for_status()
56
- questions_data = response.json()
 
 
 
 
 
 
 
57
  if not questions_data:
58
  print("Fetched questions list is empty.")
59
  return "Fetched questions list is empty or invalid format.", None
@@ -74,6 +73,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
74
  answers_payload = []
75
  print(f"Running agent on {len(questions_data)} questions...")
76
  for item in questions_data:
 
 
77
  task_id = item.get("task_id")
78
  question_text = item.get("question")
79
  if not task_id or question_text is None:
@@ -146,11 +147,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).
 
1
  import os
2
+ import time
3
  import gradio as gr
4
  import requests
5
  import inspect
6
  import pandas as pd
7
+ import json
8
+ from agent import BasicAgent
9
 
10
  # (Keep Constants as is)
11
  # --- Constants ---
12
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
13
 
 
 
 
 
 
 
 
 
 
 
 
14
  def run_and_submit_all( profile: gr.OAuthProfile | None):
15
  """
16
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
43
  # 2. Fetch Questions
44
  print(f"Fetching questions from: {questions_url}")
45
  try:
46
+ # Temporarily using questions.json to get around HTTP GET issue on questions endpoint
47
+ #response = requests.get(questions_url, timeout=15)
48
+ #response.raise_for_status()
49
+ #questions_data = response.json()
50
+ # BEGIN WORKAROUND
51
+ import json
52
+ questions_file_path = os.path.join(os.path.dirname(__file__), "questions.json")
53
+ with open(questions_file_path, 'r') as f:
54
+ questions_data = json.load(f)
55
+ # END WORKAROUND
56
  if not questions_data:
57
  print("Fetched questions list is empty.")
58
  return "Fetched questions list is empty or invalid format.", None
 
73
  answers_payload = []
74
  print(f"Running agent on {len(questions_data)} questions...")
75
  for item in questions_data:
76
+ print("Pausing 1 minute to avoid getting rate limited")
77
+ time.sleep(60.0)
78
  task_id = item.get("task_id")
79
  question_text = item.get("question")
80
  if not task_id or question_text is None:
 
147
  gr.Markdown(
148
  """
149
  **Instructions:**
 
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
  **Disclaimers:**
155
  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).