Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,30 +18,38 @@ def answer_question(question):
|
|
| 18 |
|
| 19 |
|
| 20 |
def submit_to_gaia(username, space_link):
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
"
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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")
|