Spaces:
Sleeping
Sleeping
Enhance submission logging and error handling
Browse files
app.py
CHANGED
|
@@ -80,6 +80,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 80 |
if NO_SUBMIT:
|
| 81 |
return f"Submission SKIPPED (NO_SUBMIT=True). {len(answers_payload)} answers prepared.", results_df
|
| 82 |
print(f"Submitting {len(answers_payload)} answers to: {SUBMIT_URL}")
|
|
|
|
| 83 |
try:
|
| 84 |
response = requests.post(
|
| 85 |
SUBMIT_URL, json=submission_data, timeout=max(60, len(answers_payload) * 2))
|
|
@@ -237,6 +238,8 @@ def submit_current_results_action(profile: gr.OAuthProfile | None, results_log_l
|
|
| 237 |
return f"Submission SKIPPED. {len(answers_payload)} answers ready."
|
| 238 |
|
| 239 |
gr.Info(f"Submitting {len(answers_payload)} answers for '{username}'...")
|
|
|
|
|
|
|
| 240 |
try:
|
| 241 |
response = requests.post(
|
| 242 |
SUBMIT_URL, json=submission_data, timeout=max(60, len(answers_payload)*2))
|
|
@@ -244,8 +247,16 @@ def submit_current_results_action(profile: gr.OAuthProfile | None, results_log_l
|
|
| 244 |
result_data = response.json()
|
| 245 |
return (f"Submission Successful! User: {result_data.get('username')}, Score: {result_data.get('score', 'N/A')}% "
|
| 246 |
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')}), Msg: {result_data.get('message', '')}")
|
| 247 |
-
except
|
| 248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
|
| 251 |
# --- Build Gradio Interface ---
|
|
|
|
| 80 |
if NO_SUBMIT:
|
| 81 |
return f"Submission SKIPPED (NO_SUBMIT=True). {len(answers_payload)} answers prepared.", results_df
|
| 82 |
print(f"Submitting {len(answers_payload)} answers to: {SUBMIT_URL}")
|
| 83 |
+
print("Submitting data:", json.dumps(submission_data, indent=2))
|
| 84 |
try:
|
| 85 |
response = requests.post(
|
| 86 |
SUBMIT_URL, json=submission_data, timeout=max(60, len(answers_payload) * 2))
|
|
|
|
| 238 |
return f"Submission SKIPPED. {len(answers_payload)} answers ready."
|
| 239 |
|
| 240 |
gr.Info(f"Submitting {len(answers_payload)} answers for '{username}'...")
|
| 241 |
+
print("Submitting data:", json.dumps(submission_data, indent=2))
|
| 242 |
+
|
| 243 |
try:
|
| 244 |
response = requests.post(
|
| 245 |
SUBMIT_URL, json=submission_data, timeout=max(60, len(answers_payload)*2))
|
|
|
|
| 247 |
result_data = response.json()
|
| 248 |
return (f"Submission Successful! User: {result_data.get('username')}, Score: {result_data.get('score', 'N/A')}% "
|
| 249 |
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')}), Msg: {result_data.get('message', '')}")
|
| 250 |
+
except requests.exceptions.HTTPError as e:
|
| 251 |
+
error_detail = f"Server responded with status {e.response.status_code}."
|
| 252 |
+
try:
|
| 253 |
+
error_json = e.response.json() # This is key
|
| 254 |
+
error_detail += f" Detail: {error_json.get('detail', e.response.text if e.response else 'No response text')}"
|
| 255 |
+
except requests.exceptions.JSONDecodeError:
|
| 256 |
+
error_detail += f" Response: {e.response.text[:500] if e.response else 'No response text'}"
|
| 257 |
+
status_message = f"Submission Failed: {error_detail}"
|
| 258 |
+
gr.Error(status_message)
|
| 259 |
+
return status_message
|
| 260 |
|
| 261 |
|
| 262 |
# --- Build Gradio Interface ---
|