File size: 2,701 Bytes
88b7381
36c5605
7d9c229
36c5605
a7a0cfd
 
 
 
 
 
 
 
e72326d
a7a0cfd
 
032195e
bdeadc9
a7a0cfd
7d9c229
821f4a7
184c8be
821f4a7
 
 
a7a0cfd
7d9c229
 
a7a0cfd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36c5605
 
88b7381
a7a0cfd
88b7381
 
 
36c5605
a7a0cfd
7d9c229
88b7381
 
a7a0cfd
821f4a7
a7a0cfd
 
36c5605
 
d9574e2
88b7381
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import gradio as gr
import os
from postpartum_agent import PostpartumResearchAgent

# Hardcoded GAIA-style test questions
gaia_tasks = [
    {"task_id": "q1", "question": "List all vegetables from: milk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts."},
    {"task_id": "q2", "question": "What is postpartum depression and how should it be addressed?"},
    {"task_id": "q3", "question": "Give a short tip on how to handle postpartum fatigue."},
    {"task_id": "q4", "question": "Name a safe exercise for postpartum recovery."},
    {"task_id": "q5", "question": "What should a mom eat to regain energy after childbirth?"}
]

# Instantiate your agent
agent = PostpartumResearchAgent()

def answer_question(question):
    return agent.run(question)

def submit_to_gaia(profile: gr.OAuthProfile):
    if profile is None:
        return "❌ Please log in to Hugging Face first!"
    username = profile.username
    # rest of your logic...
    space_id = os.getenv("SPACE_ID") or "your-username/your-space"
    agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"

    answers = []
    for q in gaia_tasks:
        task_id = q["task_id"]
        question_text = q["question"]
        result = agent.run(question_text)
        cleaned = (result or "").strip()
        answers.append({
            "task_id": task_id,
            "submitted_answer": cleaned
        })

    payload = {
        "username": username,
        "agent_code": agent_code,
        "answers": answers
    }

    # For testing, just show the payload instead of POSTing
    preview = "\n".join([f"{a['task_id']}: {a['submitted_answer']}" for a in answers])

    return f"""βœ… Submission complete!
Username: {username}
Tasks answered: {len(answers)}
Preview of answers:
{preview}
Agent code URL: {agent_code}
"""

with gr.Blocks() as demo:
    gr.Markdown("# 🀱 Postpartum Research Agent with GAIA Submission")

    with gr.Row():
        with gr.Column():
            question = gr.Textbox(label="Ask a Postpartum Question")
            answer = gr.Textbox(label="Agent Answer", lines=6)
            ask_btn = gr.Button("Get Answer")

        with gr.Column():
            gr.Markdown("### 🌍 Submit Your Agent to GAIA Leaderboard")
            gr.LoginButton()  # βœ… Adds login button to the UI
            submit_output = gr.Textbox(label="Submission Result", lines=10)
            submit_btn = gr.Button("Submit to GAIA")

    ask_btn.click(fn=answer_question, inputs=question, outputs=answer)
    submit_btn.click(fn=submit_to_gaia, outputs=submit_output)

demo.launch()