Spaces:
Runtime error
Runtime error
Commit ·
ce6eac2
1
Parent(s): e28f135
app
Browse files
app.py
CHANGED
|
@@ -40,6 +40,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 40 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 41 |
and displays the results.
|
| 42 |
"""
|
|
|
|
| 43 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
| 44 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
| 45 |
|
|
@@ -54,25 +55,27 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 54 |
questions_url = f"{api_url}/questions"
|
| 55 |
submit_url = f"{api_url}/submit"
|
| 56 |
|
|
|
|
| 57 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 58 |
try:
|
| 59 |
agent = BasicAgent()
|
| 60 |
except Exception as e:
|
| 61 |
print(f"Error instantiating agent: {e}")
|
| 62 |
return f"Error initializing agent: {e}", None
|
| 63 |
-
# In the case of an app running as a hugging Face space, this link points toward your codebase
|
|
|
|
| 64 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 65 |
print(agent_code)
|
| 66 |
|
| 67 |
# 2. Fetch Questions with retry mechanism
|
| 68 |
print(f"Fetching questions from: {questions_url}")
|
| 69 |
|
| 70 |
-
# Retry
|
| 71 |
session = requests.Session()
|
| 72 |
retry_strategy = Retry(
|
| 73 |
-
total=5,
|
| 74 |
-
status_forcelist=[429, 500, 502, 503, 504],
|
| 75 |
-
backoff_factor=1,
|
| 76 |
respect_retry_after_header=True
|
| 77 |
)
|
| 78 |
adapter = HTTPAdapter(max_retries=retry_strategy)
|
|
@@ -80,8 +83,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 80 |
session.mount("https://", adapter)
|
| 81 |
|
| 82 |
try:
|
| 83 |
-
#
|
| 84 |
-
time.sleep(2)
|
| 85 |
response = session.get(questions_url, timeout=30)
|
| 86 |
response.raise_for_status()
|
| 87 |
questions_data = response.json()
|
|
@@ -122,11 +125,13 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 122 |
print("Agent did not produce any answers to submit.")
|
| 123 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 124 |
|
|
|
|
| 125 |
# 4. Prepare Submission
|
| 126 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 127 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
| 128 |
print(status_update)
|
| 129 |
|
|
|
|
| 130 |
# 5. Submit with retry
|
| 131 |
print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
|
| 132 |
try:
|
|
@@ -173,6 +178,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 173 |
return status_message, results_df
|
| 174 |
|
| 175 |
|
|
|
|
| 176 |
# --- Build Gradio Interface using Blocks ---
|
| 177 |
with gr.Blocks() as demo:
|
| 178 |
gr.Markdown("# Basic Agent Evaluation Runner")
|
|
|
|
| 40 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 41 |
and displays the results.
|
| 42 |
"""
|
| 43 |
+
|
| 44 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
| 45 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
| 46 |
|
|
|
|
| 55 |
questions_url = f"{api_url}/questions"
|
| 56 |
submit_url = f"{api_url}/submit"
|
| 57 |
|
| 58 |
+
|
| 59 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 60 |
try:
|
| 61 |
agent = BasicAgent()
|
| 62 |
except Exception as e:
|
| 63 |
print(f"Error instantiating agent: {e}")
|
| 64 |
return f"Error initializing agent: {e}", None
|
| 65 |
+
# In the case of an app running as a hugging Face space, this link points toward your codebase
|
| 66 |
+
# (usefull for others so please keep it public)
|
| 67 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 68 |
print(agent_code)
|
| 69 |
|
| 70 |
# 2. Fetch Questions with retry mechanism
|
| 71 |
print(f"Fetching questions from: {questions_url}")
|
| 72 |
|
| 73 |
+
# Retry
|
| 74 |
session = requests.Session()
|
| 75 |
retry_strategy = Retry(
|
| 76 |
+
total=5,
|
| 77 |
+
status_forcelist=[429, 500, 502, 503, 504],
|
| 78 |
+
backoff_factor=1,
|
| 79 |
respect_retry_after_header=True
|
| 80 |
)
|
| 81 |
adapter = HTTPAdapter(max_retries=retry_strategy)
|
|
|
|
| 83 |
session.mount("https://", adapter)
|
| 84 |
|
| 85 |
try:
|
| 86 |
+
# rate limiter
|
| 87 |
+
time.sleep(2)
|
| 88 |
response = session.get(questions_url, timeout=30)
|
| 89 |
response.raise_for_status()
|
| 90 |
questions_data = response.json()
|
|
|
|
| 125 |
print("Agent did not produce any answers to submit.")
|
| 126 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 127 |
|
| 128 |
+
|
| 129 |
# 4. Prepare Submission
|
| 130 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 131 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
| 132 |
print(status_update)
|
| 133 |
|
| 134 |
+
|
| 135 |
# 5. Submit with retry
|
| 136 |
print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
|
| 137 |
try:
|
|
|
|
| 178 |
return status_message, results_df
|
| 179 |
|
| 180 |
|
| 181 |
+
|
| 182 |
# --- Build Gradio Interface using Blocks ---
|
| 183 |
with gr.Blocks() as demo:
|
| 184 |
gr.Markdown("# Basic Agent Evaluation Runner")
|