Update app.py
Browse filesUpdated sleep and uncommented the submit section
app.py
CHANGED
@@ -144,7 +144,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
144 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
145 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
146 |
# Sleep to avoid the Gemini throttling at 15 RPM
|
147 |
-
time.sleep(
|
148 |
except Exception as e:
|
149 |
print(f"Error running agent on task {task_id}: {e}")
|
150 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
@@ -155,53 +155,53 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
155 |
|
156 |
return "Questions parsed.", pd.DataFrame(results_log)
|
157 |
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
|
206 |
|
207 |
# --- Build Gradio Interface using Blocks ---
|
|
|
144 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
145 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
146 |
# Sleep to avoid the Gemini throttling at 15 RPM
|
147 |
+
time.sleep(45)
|
148 |
except Exception as e:
|
149 |
print(f"Error running agent on task {task_id}: {e}")
|
150 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
|
|
155 |
|
156 |
return "Questions parsed.", pd.DataFrame(results_log)
|
157 |
|
158 |
+
4. Prepare Submission
|
159 |
+
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
160 |
+
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
161 |
+
print(status_update)
|
162 |
|
163 |
+
5. Submit
|
164 |
+
print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
|
165 |
+
try:
|
166 |
+
response = requests.post(submit_url, json=submission_data, timeout=60)
|
167 |
+
response.raise_for_status()
|
168 |
+
result_data = response.json()
|
169 |
+
final_status = (
|
170 |
+
f"Submission Successful!\n"
|
171 |
+
f"User: {result_data.get('username')}\n"
|
172 |
+
f"Overall Score: {result_data.get('score', 'N/A')}% "
|
173 |
+
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
|
174 |
+
f"Message: {result_data.get('message', 'No message received.')}"
|
175 |
+
)
|
176 |
+
print("Submission successful.")
|
177 |
+
results_df = pd.DataFrame(results_log)
|
178 |
+
return final_status, results_df
|
179 |
+
except requests.exceptions.HTTPError as e:
|
180 |
+
error_detail = f"Server responded with status {e.response.status_code}."
|
181 |
+
try:
|
182 |
+
error_json = e.response.json()
|
183 |
+
error_detail += f" Detail: {error_json.get('detail', e.response.text)}"
|
184 |
+
except requests.exceptions.JSONDecodeError:
|
185 |
+
error_detail += f" Response: {e.response.text[:500]}"
|
186 |
+
status_message = f"Submission Failed: {error_detail}"
|
187 |
+
print(status_message)
|
188 |
+
results_df = pd.DataFrame(results_log)
|
189 |
+
return status_message, results_df
|
190 |
+
except requests.exceptions.Timeout:
|
191 |
+
status_message = "Submission Failed: The request timed out."
|
192 |
+
print(status_message)
|
193 |
+
results_df = pd.DataFrame(results_log)
|
194 |
+
return status_message, results_df
|
195 |
+
except requests.exceptions.RequestException as e:
|
196 |
+
status_message = f"Submission Failed: Network error - {e}"
|
197 |
+
print(status_message)
|
198 |
+
results_df = pd.DataFrame(results_log)
|
199 |
+
return status_message, results_df
|
200 |
+
except Exception as e:
|
201 |
+
status_message = f"An unexpected error occurred during submission: {e}"
|
202 |
+
print(status_message)
|
203 |
+
results_df = pd.DataFrame(results_log)
|
204 |
+
return status_message, results_df
|
205 |
|
206 |
|
207 |
# --- Build Gradio Interface using Blocks ---
|