Zeba15 commited on
Commit
ced8f6b
·
verified ·
1 Parent(s): 359a728

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -24
app.py CHANGED
@@ -18,30 +18,38 @@ def answer_question(question):
18
 
19
 
20
  def submit_to_gaia(username, space_link):
21
- # Get questions
22
- response = requests.get(f"{GAIA_API_URL}/questions")
23
- questions = response.json()
24
-
25
- answers = []
26
- for q in questions:
27
- task_id = q['task_id']
28
- question_text = q['question']
29
- agent_answer = agent.run(question_text)
30
- answers.append({
31
- "task_id": task_id,
32
- "submitted_answer": agent_answer
33
- })
34
-
35
- payload = {
36
- "username": username,
37
- "agent_code": space_link,
38
- "answers": answers
39
- }
40
-
41
- submit_response = requests.post(f"{GAIA_API_URL}/submit", json=payload)
42
- result = submit_response.json()
43
-
44
- return f"Submitted! Result: {result}"
 
 
 
 
 
 
 
 
45
 
46
  with gr.Blocks() as demo:
47
  gr.Markdown("# 🤱 Postpartum Research Agent")
 
18
 
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:
55
  gr.Markdown("# 🤱 Postpartum Research Agent")