yoshizen commited on
Commit
2cd7110
·
verified ·
1 Parent(s): da09e0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -8,6 +8,7 @@ import gradio as gr
8
  import requests
9
  import json
10
  import re
 
11
 
12
  # Configure logging
13
  logging.basicConfig(level=logging.INFO,
@@ -270,10 +271,10 @@ def run_agent_on_questions(agent, questions):
270
  # Get answer from agent
271
  answer = agent.answer(question_text)
272
 
273
- # Add to answers list
274
  answers.append({
275
  "task_id": task_id,
276
- "submitted_answer": answer
277
  })
278
 
279
  logger.info(f"Task {task_id}: '{question_text[:50]}...' -> '{answer}'")
@@ -284,13 +285,17 @@ def submit_answers(answers, username, api_url=DEFAULT_API_URL):
284
  """Submit answers to the API"""
285
  logger.info(f"Submitting {len(answers)} answers for user '{username}'...")
286
 
287
- # Prepare payload
288
- payload = {
289
- "username": username,
290
- "answers": answers
291
- }
292
-
293
  try:
 
 
 
 
 
 
 
 
 
 
294
  # Submit answers
295
  response = requests.post(f"{api_url}/submit", json=payload)
296
  response.raise_for_status()
@@ -302,7 +307,8 @@ def submit_answers(answers, username, api_url=DEFAULT_API_URL):
302
 
303
  return result
304
  except Exception as e:
305
- logger.error(f"Error submitting answers: {e}")
 
306
  return {"error": str(e)}
307
 
308
  def run_and_submit_all(username_input, *args):
 
8
  import requests
9
  import json
10
  import re
11
+ import traceback
12
 
13
  # Configure logging
14
  logging.basicConfig(level=logging.INFO,
 
271
  # Get answer from agent
272
  answer = agent.answer(question_text)
273
 
274
+ # Add to answers list with the correct format
275
  answers.append({
276
  "task_id": task_id,
277
+ "answer": answer # Changed from "submitted_answer" to "answer"
278
  })
279
 
280
  logger.info(f"Task {task_id}: '{question_text[:50]}...' -> '{answer}'")
 
285
  """Submit answers to the API"""
286
  logger.info(f"Submitting {len(answers)} answers for user '{username}'...")
287
 
 
 
 
 
 
 
288
  try:
289
+ # FIXED: Format the payload correctly according to API expectations
290
+ # The server expects a specific format with agent_code and answers
291
+ payload = {
292
+ "agent_code": f"https://huggingface.co/spaces/{username}/Final_Assignment_Template/blob/main/app.py",
293
+ "answers": answers
294
+ }
295
+
296
+ # Log the payload for debugging
297
+ logger.info(f"Submission payload: {json.dumps(payload, indent=2)}")
298
+
299
  # Submit answers
300
  response = requests.post(f"{api_url}/submit", json=payload)
301
  response.raise_for_status()
 
307
 
308
  return result
309
  except Exception as e:
310
+ logger.error(f"Error submitting answers: {str(e)}")
311
+ logger.error(traceback.format_exc())
312
  return {"error": str(e)}
313
 
314
  def run_and_submit_all(username_input, *args):