Zeba15 commited on
Commit
2b1c25c
Β·
verified Β·
1 Parent(s): ced8f6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -20
app.py CHANGED
@@ -19,36 +19,65 @@ def answer_question(question):
19
 
20
  def submit_to_gaia(username, space_link):
21
  GAIA_API_URL = "https://huggingface.co/api/gaia"
22
-
23
  try:
24
- # 1. Fetch tasks from GAIA
25
  response = requests.get(f"{GAIA_API_URL}/questions")
26
- questions = response.json() # Now properly parsed into a list of dicts
 
 
 
 
 
27
 
28
- # 2. Generate answers using your agent
29
  answers = []
30
- for q in questions:
31
- task_id = q["task_id"]
32
- question_text = q["question"]
33
- agent_answer = agent.search_advice(question_text) # Use your semantic search
34
- answers.append({
35
- "task_id": task_id,
36
- "submitted_answer": agent_answer.strip()
37
- })
38
-
39
- # 3. Submit answers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  payload = {
41
- "username": username,
42
- "agent_code": space_link,
43
  "answers": answers
44
  }
 
 
45
  submit_response = requests.post(f"{GAIA_API_URL}/submit", json=payload)
46
- result = submit_response.json()
47
 
48
- return f"βœ… Submission complete!\n\nScore: {result.get('score', 'N/A')}\nStatus: {result.get('status', 'N/A')}\nMessage: {result.get('message', 'No message')}"
49
-
 
 
 
 
 
 
 
 
 
50
  except Exception as e:
51
- return f"❌ Submission failed due to: {str(e)}"
 
52
 
53
 
54
  with gr.Blocks() as demo:
 
19
 
20
  def submit_to_gaia(username, space_link):
21
  GAIA_API_URL = "https://huggingface.co/api/gaia"
22
+
23
  try:
24
+ # Step 1: Fetch questions
25
  response = requests.get(f"{GAIA_API_URL}/questions")
26
+ if response.status_code != 200:
27
+ return f"❌ Failed to fetch tasks. HTTP {response.status_code}: {response.text}"
28
+
29
+ questions = response.json()
30
+ if not isinstance(questions, list):
31
+ return f"❌ Unexpected response format: {questions}"
32
 
 
33
  answers = []
34
+ for idx, q in enumerate(questions):
35
+ try:
36
+ task_id = q["task_id"]
37
+ question_text = q["question"]
38
+ print(f"➑️ [{idx+1}/{len(questions)}] Answering: {question_text}")
39
+
40
+ agent_answer = agent.search_advice(question_text)
41
+ cleaned_answer = (agent_answer or "").strip()
42
+
43
+ if not cleaned_answer:
44
+ print(f"⚠️ Warning: Empty answer for task {task_id}")
45
+
46
+ answers.append({
47
+ "task_id": task_id,
48
+ "submitted_answer": cleaned_answer
49
+ })
50
+
51
+ except Exception as inner_e:
52
+ print(f"❌ Error on question {idx+1}: {inner_e}")
53
+ continue
54
+
55
+ if not answers:
56
+ return "❌ No answers were collected. All tasks failed or returned empty."
57
+
58
  payload = {
59
+ "username": username.strip(),
60
+ "agent_code": space_link.strip(),
61
  "answers": answers
62
  }
63
+
64
+ print("πŸš€ Submitting answers to GAIA...")
65
  submit_response = requests.post(f"{GAIA_API_URL}/submit", json=payload)
 
66
 
67
+ try:
68
+ result = submit_response.json()
69
+ except Exception:
70
+ return f"❌ Failed to parse submission response:\n{submit_response.text}"
71
+
72
+ return f"""βœ… Submission complete!
73
+ Score: {result.get('score', 'N/A')}
74
+ Status: {result.get('status', 'N/A')}
75
+ Message: {result.get('message', 'No message')}
76
+ """
77
+
78
  except Exception as e:
79
+ return f"❌ Submission failed: {str(e)}"
80
+
81
 
82
 
83
  with gr.Blocks() as demo: