File size: 3,358 Bytes
2650708
 
 
 
 
10e9b7d
2650708
 
 
 
 
 
10e9b7d
2650708
 
 
e80aab9
2650708
 
 
 
 
 
 
 
4021bf3
2650708
31243f4
2650708
 
31243f4
2650708
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e80aab9
2650708
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e80aab9
2650708
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
Hugging Face Space implementation for Personal Task Manager Agent
This file serves as the entry point for the Hugging Face Space
"""

import gradio as gr
from task_manager_agent import TaskManagerAgent
import json
import os

# Initialize the agent
agent = TaskManagerAgent()

# Try to load existing tasks if available
if os.path.exists("tasks.json"):
    agent.load_state("tasks.json")

def process_message(message, history):
    """Process user message and return agent response"""
    response = agent.process_query(message)
    
    # Save state after each interaction
    agent.save_state("tasks.json")
    
    return response

def get_gaia_answer(question):
    """
    Function to process GAIA benchmark questions
    This is the function that will be called by the GAIA API
    """
    # Process the question with our agent
    response = agent.process_query(question)
    
    # For GAIA benchmark, we need to return just the answer without any formatting
    # Strip any extra formatting that might be in the response
    clean_response = response.strip()
    
    return clean_response

# Create Gradio interface
with gr.Blocks(title="Personal Task Manager Agent") as demo:
    gr.Markdown("# Personal Task Manager Agent")
    gr.Markdown("""
    This agent helps you manage tasks through natural language commands.
    
    ## Example commands:
    - Add a task: "Add a new task to buy groceries"
    - Add with details: "Add task to call mom priority:high due:2023-05-20 category:personal"
    - List tasks: "Show me my tasks" or "What do I need to do?"
    - Complete a task: "Mark task 2 as done" or "I completed task 3"
    - Delete a task: "Delete task 1" or "Remove task 4"
    - Filter tasks: "Show high priority tasks" or "List personal tasks"
    - Get help: "Help me" or "What can you do?"
    """)
    
    chatbot = gr.Chatbot(height=400)
    msg = gr.Textbox(label="Type your command here")
    clear = gr.Button("Clear")
    
    def user(message, history):
        return "", history + [[message, None]]
    
    def bot(history):
        message = history[-1][0]
        response = process_message(message, history)
        history[-1][1] = response
        return history
    
    msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
        bot, chatbot, chatbot
    )
    
    clear.click(lambda: None, None, chatbot, queue=False)
    
    # Add GAIA API endpoint explanation
    gr.Markdown("""
    ## GAIA Benchmark API
    
    This Space includes an API endpoint for the GAIA benchmark. The API processes questions 
    and returns answers in the format expected by the benchmark.
    
    The endpoint is automatically available when deployed on Hugging Face Spaces.
    """)

# For GAIA API endpoint
def gaia_api(question):
    """API endpoint for GAIA benchmark"""
    answer = get_gaia_answer(question)
    return {"answer": answer}

# Launch the app
if __name__ == "__main__":
    # Set up FastAPI for GAIA benchmark
    from fastapi import FastAPI, Request
    import uvicorn
    from pydantic import BaseModel
    
    app = FastAPI()
    
    class Question(BaseModel):
        question: str
    
    @app.post("/api/gaia")
    async def api_gaia(question: Question):
        return gaia_api(question.question)
    
    # Mount Gradio app
    demo.launch(server_name="0.0.0.0", server_port=7860)