Update app.py
Browse files
app.py
CHANGED
|
@@ -140,14 +140,12 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 140 |
except Exception as e:
|
| 141 |
return f"Error initializing agent: {e}", None
|
| 142 |
|
| 143 |
-
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 144 |
|
| 145 |
try:
|
| 146 |
response = requests.get(questions_url, timeout=15)
|
| 147 |
response.raise_for_status()
|
| 148 |
questions_data = response.json()
|
| 149 |
-
if not questions_data:
|
| 150 |
-
return "Fetched questions list is empty or invalid format.", None
|
| 151 |
except Exception as e:
|
| 152 |
return f"Error fetching questions: {e}", None
|
| 153 |
|
|
@@ -163,23 +161,35 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 163 |
if not task_id or question_text is None:
|
| 164 |
continue
|
| 165 |
|
|
|
|
| 166 |
try:
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
except Exception as e:
|
| 171 |
error_message = f"AGENT ERROR: {e}"
|
| 172 |
print(f"Error running agent on task {task_id}: {e}")
|
| 173 |
print(traceback.format_exc())
|
| 174 |
-
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": error_message})
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
time.sleep(20)
|
| 179 |
|
| 180 |
if not answers_payload:
|
| 181 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 182 |
|
|
|
|
| 183 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 184 |
|
| 185 |
try:
|
|
|
|
| 140 |
except Exception as e:
|
| 141 |
return f"Error initializing agent: {e}", None
|
| 142 |
|
| 143 |
+
agent_code = f"[https://huggingface.co/spaces/](https://huggingface.co/spaces/){space_id}/tree/main"
|
| 144 |
|
| 145 |
try:
|
| 146 |
response = requests.get(questions_url, timeout=15)
|
| 147 |
response.raise_for_status()
|
| 148 |
questions_data = response.json()
|
|
|
|
|
|
|
| 149 |
except Exception as e:
|
| 150 |
return f"Error fetching questions: {e}", None
|
| 151 |
|
|
|
|
| 161 |
if not task_id or question_text is None:
|
| 162 |
continue
|
| 163 |
|
| 164 |
+
# --- MODIFICATION: Handle the dictionary output from the agent ---
|
| 165 |
try:
|
| 166 |
+
agent_result = agent(question_text)
|
| 167 |
+
# Build the payload with the required keys for submission
|
| 168 |
+
answers_payload.append({
|
| 169 |
+
"task_id": task_id,
|
| 170 |
+
"model_answer": agent_result["model_answer"],
|
| 171 |
+
"reasoning_trace": agent_result["reasoning_trace"]
|
| 172 |
+
})
|
| 173 |
+
# Log for display in the UI
|
| 174 |
+
results_log.append({
|
| 175 |
+
"Task ID": task_id,
|
| 176 |
+
"Question": question_text,
|
| 177 |
+
"Submitted Answer": agent_result["model_answer"],
|
| 178 |
+
"Reasoning Trace": agent_result["reasoning_trace"]
|
| 179 |
+
})
|
| 180 |
except Exception as e:
|
| 181 |
error_message = f"AGENT ERROR: {e}"
|
| 182 |
print(f"Error running agent on task {task_id}: {e}")
|
| 183 |
print(traceback.format_exc())
|
| 184 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": error_message, "Reasoning Trace": ""})
|
| 185 |
+
|
| 186 |
+
print("Pausing for 5 seconds to respect API rate limits...")
|
| 187 |
+
time.sleep(5)
|
|
|
|
| 188 |
|
| 189 |
if not answers_payload:
|
| 190 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 191 |
|
| 192 |
+
# The submission payload is now a list of dictionaries with the correct keys
|
| 193 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 194 |
|
| 195 |
try:
|