Spaces:
Sleeping
Sleeping
Przemyslaw Chachaj commited on
Commit ·
b019af3
1
Parent(s): fc4b20e
Add Gradio MCP habit agent
Browse files- app.py +53 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# === TOOLS ===
|
| 4 |
+
|
| 5 |
+
def create_contract(link: str, uid: str = "default", category: str = "general"):
|
| 6 |
+
"""
|
| 7 |
+
Create a habit contract from link (Instagram reel / article / etc.)
|
| 8 |
+
|
| 9 |
+
Args:
|
| 10 |
+
link: URL to content (reel / video / article).
|
| 11 |
+
uid: User id (e.g. "szef_1").
|
| 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 |
+
def next_step(uid: str):
|
| 23 |
+
"""
|
| 24 |
+
Returns next habit step for contract holder.
|
| 25 |
+
|
| 26 |
+
Args:
|
| 27 |
+
uid: User id that has a contract.
|
| 28 |
+
|
| 29 |
+
Returns:
|
| 30 |
+
Text with next step.
|
| 31 |
+
"""
|
| 32 |
+
return f"Next step for {uid}: do one tiny action now."
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# === UI (opcjonalne, dla podglądu) ===
|
| 36 |
+
|
| 37 |
+
demo = gr.Interface(
|
| 38 |
+
fn=create_contract,
|
| 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 |
+
# 🚀 KRYTYCZNE: MCP SERVER
|
| 53 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio[mcp]
|