File size: 2,670 Bytes
de5b666
 
efe51c1
 
 
 
 
 
de5b666
 
 
 
efe51c1
 
 
 
 
de5b666
efe51c1
de5b666
 
efe51c1
 
 
 
 
 
de5b666
 
 
 
 
efe51c1
 
 
 
 
 
 
de5b666
efe51c1
 
 
 
 
 
de5b666
efe51c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5057a0d
efe51c1
3d46d3a
 
efe51c1
 
3d46d3a
5057a0d
efe51c1
 
 
 
ffc38d8
efe51c1
5057a0d
de5b666
 
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
import gradio as gr
import os
from typing import Dict, List, Union, Any
import logging

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

from llm_parser import llm_parse_tasks
from notion_handler import create_tasks_database, push_tasks_to_notion

def organize_goals_into_notion(user_input: str) -> Dict[str, Any]:
    """
    Process a single goal into Notion tasks.
    Returns a dictionary with success status and detailed response.
    """
    try:
        logger.info(f"Processing user input: {user_input}")
        tasks = llm_parse_tasks(user_input)
        if isinstance(tasks, str):
            logger.error(f"Failed to parse tasks: {tasks}")
            return {
                "success": False,
                "error": "Failed to parse tasks",
                "details": tasks
            }
        
        db_id = create_tasks_database()
        push_tasks_to_notion(tasks, db_id)

        task_names = [t.get("task", "Untitled") for t in tasks]
        logger.info(f"Successfully created {len(task_names)} tasks")
        return {
            "success": True,
            "message": f"✅ {len(task_names)} tasks added to Notion",
            "tasks": task_names,
            "database_id": db_id
        }
    except Exception as e:
        logger.error(f"Error processing request: {str(e)}")
        return {
            "success": False,
            "error": str(e),
            "details": "An error occurred while processing your request"
        }

# Create Gradio interface
demo = gr.Interface(
    fn=organize_goals_into_notion,
    inputs=gr.Textbox(
        lines=4,
        placeholder="What do you want to get done this week?",
        label="Your Goals"
    ),
    outputs=gr.JSON(label="Results"),
    title="🧠 NotionTaskSense",
    description="Turn your goals into structured Notion tasks",
    examples=[
        ["I need to update my resume, apply to 3 jobs, and study for AWS certification"],
        ["Meet with team about project timeline, prepare presentation for client, and follow up on pending emails"],
    ],
    theme=gr.themes.Soft()
)

# Add MCP metadata
organize_goals_into_notion.mcp_type = "function"
organize_goals_into_notion.mcp_description = "Organize goals into structured Notion tasks. Input should be a natural language description of tasks or goals."
organize_goals_into_notion.mcp_input_type = "string"
organize_goals_into_notion.mcp_output_type = "json"
organize_goals_into_notion.mcp_name = "organize_goals_into_notion"

if __name__ == "__main__":
    demo.queue().launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=False
    )