Spaces:
Sleeping
Sleeping
Przemyslaw Chachaj commited on
Commit ·
7271b67
1
Parent(s): b019af3
FIX working minimal MCP server
Browse files
app.py
CHANGED
|
@@ -1,53 +1,37 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
# === TOOLS ===
|
| 4 |
|
| 5 |
-
def create_contract(link: str,
|
| 6 |
"""
|
| 7 |
-
Create a habit contract from
|
| 8 |
|
| 9 |
Args:
|
| 10 |
-
link: URL to
|
| 11 |
-
|
| 12 |
-
category: Habit category (e.g. "career", "health").
|
| 13 |
-
"""
|
| 14 |
-
return {
|
| 15 |
-
"status": "created",
|
| 16 |
-
"uid": uid,
|
| 17 |
-
"source": link,
|
| 18 |
-
"category": category
|
| 19 |
-
}
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
"""
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
uid:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
Returns:
|
| 30 |
-
Text with next step.
|
| 31 |
-
"""
|
| 32 |
-
return f"Next step for {uid}: do one tiny action now."
|
| 33 |
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
inputs=[
|
| 40 |
-
gr.Textbox(label="Link"),
|
| 41 |
-
gr.Textbox(label="UID", value="szef_1"),
|
| 42 |
-
gr.Textbox(label="Category", value="career"),
|
| 43 |
-
],
|
| 44 |
-
outputs="json",
|
| 45 |
-
title="Habit Agent MCP Server",
|
| 46 |
-
description="Create habit contracts and get next steps via MCP tools."
|
| 47 |
-
)
|
| 48 |
|
| 49 |
-
# Ten tool nie ma UI, ale jest widoczny jako MCP tool:
|
| 50 |
-
gr.api(next_step)
|
| 51 |
|
| 52 |
-
|
| 53 |
-
demo.launch(mcp_server=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
| 3 |
|
| 4 |
+
def create_contract(link: str, category: str = "general") -> dict:
|
| 5 |
"""
|
| 6 |
+
Create a simple habit contract from a reel link.
|
| 7 |
|
| 8 |
Args:
|
| 9 |
+
link: URL to the reel / content.
|
| 10 |
+
category: Area of life (e.g. career, health, relationships).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
Returns:
|
| 13 |
+
JSON with a fake uid, echo of params and first tiny step.
|
| 14 |
"""
|
| 15 |
+
if not link:
|
| 16 |
+
return {"error": "link is required"}
|
| 17 |
|
| 18 |
+
return {
|
| 19 |
+
"uid": f"demo_{category}",
|
| 20 |
+
"link": link,
|
| 21 |
+
"category": category,
|
| 22 |
+
"next_step": "Watch the reel and take ONE practical action today."
|
| 23 |
+
}
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
with gr.Blocks() as demo:
|
| 27 |
+
gr.Markdown("# Behavior Changer – MCP Demo")
|
| 28 |
|
| 29 |
+
link = gr.Textbox(label="Reel/link", placeholder="https://instagram.com/reel/...")
|
| 30 |
+
category = gr.Textbox(label="Category", value="career")
|
| 31 |
+
out = gr.JSON(label="Result JSON")
|
| 32 |
|
| 33 |
+
btn = gr.Button("Generate Contract")
|
| 34 |
+
btn.click(create_contract, [link, category], out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
demo.launch(mcp_server=True)
|
|
|