GoodLuckChuck commited on
Commit
f76da28
·
verified ·
1 Parent(s): ea2ac49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -14
app.py CHANGED
@@ -424,30 +424,51 @@ def api_submit_answers(processed_answers: List[Dict[str, Any]], username: str) -
424
  submission_data = {
425
  "username": username,
426
  "agent_code": AGENT_CODE_IDENTIFIER,
427
- "answers": processed_answers # Now in correct format: {"task_id": "...", "model_answer": "..."}
428
  }
429
 
430
  print("\n=== Submission Details ===")
431
  print(f"Username: {username}")
432
  print(f"Agent Code: {AGENT_CODE_IDENTIFIER}")
433
  print(f"Number of Answers: {len(processed_answers)}")
 
 
434
 
435
  response = requests.post(
436
  f"{API_BASE_URL}/submit",
437
  headers=HEADERS,
438
- json=submission_data
 
439
  )
440
- response.raise_for_status()
441
 
442
- result = response.json()
443
- print(f"\nSubmission Response:\n{json.dumps(result, indent=2)}")
444
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
445
 
446
  except requests.exceptions.RequestException as e:
447
- print(f"\nError submitting answers to API: {str(e)}")
448
- if hasattr(e.response, 'text'):
449
- print(f"API Error Response: {e.response.text}")
450
- return {}
 
 
 
 
 
 
451
 
452
  def run_and_submit_all(profile: gr.OAuthProfile | None):
453
  """Process questions and submit answers"""
@@ -478,11 +499,12 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
478
  answer = asyncio.run(agent.process_question(question_text))
479
 
480
  # Format answer in required JSONL format
481
- answers_payload.append({
482
  "task_id": task_id,
483
  "model_answer": answer.text
484
- # Removed reasoning_trace as it's optional
485
- })
 
486
 
487
  # Keep detailed logs for display only
488
  results_log.append({
@@ -507,6 +529,13 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
507
  print("\nSubmitting answers to API...")
508
  submission_result = api_submit_answers(answers_payload, profile.username)
509
 
 
 
 
 
 
 
 
510
  if submission_result:
511
  status = (
512
  f"Submission Successful!\n"
@@ -516,13 +545,15 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
516
  f"Message: {submission_result.get('message', 'No message received.')}"
517
  )
518
  else:
519
- status = "Submission failed. Check logs for details."
520
 
521
  return status, pd.DataFrame(results_log)
522
 
523
  except Exception as e:
524
  error_msg = f"Error in processing: {str(e)}"
525
  print(error_msg)
 
 
526
  return error_msg, None
527
 
528
  # Create Gradio interface
 
424
  submission_data = {
425
  "username": username,
426
  "agent_code": AGENT_CODE_IDENTIFIER,
427
+ "answers": processed_answers
428
  }
429
 
430
  print("\n=== Submission Details ===")
431
  print(f"Username: {username}")
432
  print(f"Agent Code: {AGENT_CODE_IDENTIFIER}")
433
  print(f"Number of Answers: {len(processed_answers)}")
434
+ print(f"Sample answer format: {json.dumps(processed_answers[0], indent=2) if processed_answers else 'No answers'}")
435
+ print(f"\nFull submission data: {json.dumps(submission_data, indent=2)}")
436
 
437
  response = requests.post(
438
  f"{API_BASE_URL}/submit",
439
  headers=HEADERS,
440
+ json=submission_data,
441
+ timeout=30 # Add timeout
442
  )
 
443
 
444
+ print(f"\nResponse status code: {response.status_code}")
445
+ print(f"Response headers: {dict(response.headers)}")
446
+
447
+ try:
448
+ response_text = response.text
449
+ print(f"Raw response: {response_text}")
450
+ response.raise_for_status()
451
+ result = response.json()
452
+ print(f"Parsed response: {json.dumps(result, indent=2)}")
453
+ return result
454
+ except json.JSONDecodeError as je:
455
+ print(f"Failed to parse response as JSON: {je}")
456
+ return {"error": "Invalid JSON response", "raw_response": response_text}
457
+ except requests.exceptions.HTTPError as he:
458
+ print(f"HTTP error occurred: {he}")
459
+ return {"error": f"HTTP {response.status_code}", "raw_response": response_text}
460
 
461
  except requests.exceptions.RequestException as e:
462
+ error_msg = f"Request error: {str(e)}"
463
+ print(f"\nError submitting answers to API: {error_msg}")
464
+ if hasattr(e, 'response') and e.response is not None:
465
+ print(f"Response status code: {e.response.status_code}")
466
+ print(f"Response text: {e.response.text}")
467
+ return {"error": error_msg}
468
+ except Exception as e:
469
+ error_msg = f"Unexpected error: {str(e)}"
470
+ print(f"\nError: {error_msg}")
471
+ return {"error": error_msg}
472
 
473
  def run_and_submit_all(profile: gr.OAuthProfile | None):
474
  """Process questions and submit answers"""
 
499
  answer = asyncio.run(agent.process_question(question_text))
500
 
501
  # Format answer in required JSONL format
502
+ answer_entry = {
503
  "task_id": task_id,
504
  "model_answer": answer.text
505
+ }
506
+ answers_payload.append(answer_entry)
507
+ print(f"Formatted answer: {json.dumps(answer_entry, indent=2)}")
508
 
509
  # Keep detailed logs for display only
510
  results_log.append({
 
529
  print("\nSubmitting answers to API...")
530
  submission_result = api_submit_answers(answers_payload, profile.username)
531
 
532
+ if submission_result.get('error'):
533
+ error_msg = f"Submission failed: {submission_result['error']}"
534
+ if 'raw_response' in submission_result:
535
+ error_msg += f"\nAPI Response: {submission_result['raw_response']}"
536
+ print(error_msg)
537
+ return error_msg, pd.DataFrame(results_log)
538
+
539
  if submission_result:
540
  status = (
541
  f"Submission Successful!\n"
 
545
  f"Message: {submission_result.get('message', 'No message received.')}"
546
  )
547
  else:
548
+ status = "Submission failed: No response from API"
549
 
550
  return status, pd.DataFrame(results_log)
551
 
552
  except Exception as e:
553
  error_msg = f"Error in processing: {str(e)}"
554
  print(error_msg)
555
+ import traceback
556
+ print(f"Traceback: {traceback.format_exc()}")
557
  return error_msg, None
558
 
559
  # Create Gradio interface