NotionTaskSense / app.py
srinikhildurisetti's picture
Remove api_name parameter to fix runtime error
ffc38d8
raw
history blame
2.67 kB
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
)