Commit
·
ab7953b
1
Parent(s):
96acbd9
better agent submition
Browse files
app.py
CHANGED
|
@@ -85,7 +85,10 @@ async def generate_answers(profile: gr.OAuthProfile | None, progress=gr.Progress
|
|
| 85 |
return {"Task ID": task_id, "Question": question_text, "Submitted Answer": "SKIPPED"}, None
|
| 86 |
try:
|
| 87 |
submitted_answer = await agent.aquery(question_text)
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
| 89 |
except Exception as e:
|
| 90 |
print(f"Error running agent on task {task_id}: {e}")
|
| 91 |
return {"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"}, None
|
|
@@ -122,12 +125,28 @@ def submit_answers(profile: gr.OAuthProfile | None):
|
|
| 122 |
api_url = DEFAULT_API_URL
|
| 123 |
submit_url = f"{api_url}/submit"
|
| 124 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": cached_answers}
|
| 126 |
print(f"Submitting {len(cached_answers)} answers to: {submit_url}")
|
| 127 |
try:
|
| 128 |
response = requests.post(submit_url, json=submission_data, timeout=60)
|
| 129 |
response.raise_for_status()
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
final_status = (
|
| 132 |
f"Submission Successful!\n"
|
| 133 |
f"User: {result_data.get('username')}\n"
|
|
|
|
| 85 |
return {"Task ID": task_id, "Question": question_text, "Submitted Answer": "SKIPPED"}, None
|
| 86 |
try:
|
| 87 |
submitted_answer = await agent.aquery(question_text)
|
| 88 |
+
# Ensure consistent data types for payload
|
| 89 |
+
safe_task_id = str(task_id)
|
| 90 |
+
safe_answer = str(submitted_answer)
|
| 91 |
+
return {"Task ID": safe_task_id, "Question": question_text, "Submitted Answer": safe_answer}, {"task_id": safe_task_id, "submitted_answer": safe_answer}
|
| 92 |
except Exception as e:
|
| 93 |
print(f"Error running agent on task {task_id}: {e}")
|
| 94 |
return {"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"}, None
|
|
|
|
| 125 |
api_url = DEFAULT_API_URL
|
| 126 |
submit_url = f"{api_url}/submit"
|
| 127 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 128 |
+
# Detailed logging for the submission payload (only first 3 answers to avoid clutter)
|
| 129 |
+
preview_answers = cached_answers[:3] if cached_answers else []
|
| 130 |
+
print("\n--- Submission Payload Preview ---")
|
| 131 |
+
print(f"Username: {username.strip()}")
|
| 132 |
+
print(f"Agent Code: {agent_code}")
|
| 133 |
+
print(f"Total Answers: {len(cached_answers)}")
|
| 134 |
+
print(f"First Answers Sample: {preview_answers}")
|
| 135 |
+
print("----------------------------------\n")
|
| 136 |
+
|
| 137 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": cached_answers}
|
| 138 |
print(f"Submitting {len(cached_answers)} answers to: {submit_url}")
|
| 139 |
try:
|
| 140 |
response = requests.post(submit_url, json=submission_data, timeout=60)
|
| 141 |
response.raise_for_status()
|
| 142 |
+
print(f"Submit endpoint status code: {response.status_code}")
|
| 143 |
+
print(f"Raw response text: {response.text[:500]}")
|
| 144 |
+
# Attempt to parse JSON regardless of status for troubleshooting
|
| 145 |
+
try:
|
| 146 |
+
result_data = response.json()
|
| 147 |
+
except Exception as json_err:
|
| 148 |
+
print(f"Error parsing JSON response: {json_err}")
|
| 149 |
+
raise
|
| 150 |
final_status = (
|
| 151 |
f"Submission Successful!\n"
|
| 152 |
f"User: {result_data.get('username')}\n"
|