Spaces:
Configuration error
Configuration error
Delete app.py
Browse files
app.py
DELETED
@@ -1,109 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Hugging Face Space implementation for Personal Task Manager Agent
|
3 |
-
This file serves as the entry point for the Hugging Face Space
|
4 |
-
"""
|
5 |
-
|
6 |
-
import gradio as gr
|
7 |
-
from task_manager_agent import TaskManagerAgent
|
8 |
-
import json
|
9 |
-
import os
|
10 |
-
|
11 |
-
# Initialize the agent
|
12 |
-
agent = TaskManagerAgent()
|
13 |
-
|
14 |
-
# Try to load existing tasks if available
|
15 |
-
if os.path.exists("tasks.json"):
|
16 |
-
agent.load_state("tasks.json")
|
17 |
-
|
18 |
-
def process_message(message, history):
|
19 |
-
"""Process user message and return agent response"""
|
20 |
-
response = agent.process_query(message)
|
21 |
-
|
22 |
-
# Save state after each interaction
|
23 |
-
agent.save_state("tasks.json")
|
24 |
-
|
25 |
-
return response
|
26 |
-
|
27 |
-
def get_gaia_answer(question):
|
28 |
-
"""
|
29 |
-
Function to process GAIA benchmark questions
|
30 |
-
This is the function that will be called by the GAIA API
|
31 |
-
"""
|
32 |
-
# Process the question with our agent
|
33 |
-
response = agent.process_query(question)
|
34 |
-
|
35 |
-
# For GAIA benchmark, we need to return just the answer without any formatting
|
36 |
-
# Strip any extra formatting that might be in the response
|
37 |
-
clean_response = response.strip()
|
38 |
-
|
39 |
-
return clean_response
|
40 |
-
|
41 |
-
# Create Gradio interface
|
42 |
-
with gr.Blocks(title="Personal Task Manager Agent") as demo:
|
43 |
-
gr.Markdown("# Personal Task Manager Agent")
|
44 |
-
gr.Markdown("""
|
45 |
-
This agent helps you manage tasks through natural language commands.
|
46 |
-
|
47 |
-
## Example commands:
|
48 |
-
- Add a task: "Add a new task to buy groceries"
|
49 |
-
- Add with details: "Add task to call mom priority:high due:2023-05-20 category:personal"
|
50 |
-
- List tasks: "Show me my tasks" or "What do I need to do?"
|
51 |
-
- Complete a task: "Mark task 2 as done" or "I completed task 3"
|
52 |
-
- Delete a task: "Delete task 1" or "Remove task 4"
|
53 |
-
- Filter tasks: "Show high priority tasks" or "List personal tasks"
|
54 |
-
- Get help: "Help me" or "What can you do?"
|
55 |
-
""")
|
56 |
-
|
57 |
-
chatbot = gr.Chatbot(height=400)
|
58 |
-
msg = gr.Textbox(label="Type your command here")
|
59 |
-
clear = gr.Button("Clear")
|
60 |
-
|
61 |
-
def user(message, history):
|
62 |
-
return "", history + [[message, None]]
|
63 |
-
|
64 |
-
def bot(history):
|
65 |
-
message = history[-1][0]
|
66 |
-
response = process_message(message, history)
|
67 |
-
history[-1][1] = response
|
68 |
-
return history
|
69 |
-
|
70 |
-
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
71 |
-
bot, chatbot, chatbot
|
72 |
-
)
|
73 |
-
|
74 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
75 |
-
|
76 |
-
# Add GAIA API endpoint explanation
|
77 |
-
gr.Markdown("""
|
78 |
-
## GAIA Benchmark API
|
79 |
-
|
80 |
-
This Space includes an API endpoint for the GAIA benchmark. The API processes questions
|
81 |
-
and returns answers in the format expected by the benchmark.
|
82 |
-
|
83 |
-
The endpoint is automatically available when deployed on Hugging Face Spaces.
|
84 |
-
""")
|
85 |
-
|
86 |
-
# For GAIA API endpoint
|
87 |
-
def gaia_api(question):
|
88 |
-
"""API endpoint for GAIA benchmark"""
|
89 |
-
answer = get_gaia_answer(question)
|
90 |
-
return {"answer": answer}
|
91 |
-
|
92 |
-
# Launch the app
|
93 |
-
if __name__ == "__main__":
|
94 |
-
# Set up FastAPI for GAIA benchmark
|
95 |
-
from fastapi import FastAPI, Request
|
96 |
-
import uvicorn
|
97 |
-
from pydantic import BaseModel
|
98 |
-
|
99 |
-
app = FastAPI()
|
100 |
-
|
101 |
-
class Question(BaseModel):
|
102 |
-
question: str
|
103 |
-
|
104 |
-
@app.post("/api/gaia")
|
105 |
-
async def api_gaia(question: Question):
|
106 |
-
return gaia_api(question.question)
|
107 |
-
|
108 |
-
# Mount Gradio app
|
109 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|