Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,19 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
from
|
| 4 |
-
import zoneinfo
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
name="datetime",
|
| 9 |
-
stateless_http=True, # no auth/state, HTTP transport
|
| 10 |
-
# json_response=True, # optional: force JSON-only if your client prefers it
|
| 11 |
-
)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# (Optional) tiny root page so Spaces shows something at "/"
|
| 26 |
-
@app.get("/")
|
| 27 |
-
def root():
|
| 28 |
-
return {"ok": True, "mcp": "/mcp"}
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from datetime import datetime, timezone
|
|
|
|
| 4 |
|
| 5 |
+
def now_utc():
|
| 6 |
+
yield datetime.now(timezone.utc).isoformat()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
with gr.Blocks() as demo:
|
| 9 |
+
gr.Markdown("# Datetime MCP Server (UTC)")
|
| 10 |
+
out = gr.Textbox(label="Current Time (UTC)")
|
| 11 |
+
btn = gr.Button("Get Time")
|
| 12 |
+
btn.click(now_utc, None, out, stream=True)
|
| 13 |
|
| 14 |
+
# IMPORTANT: `demo.queue()` is required for SSE streaming in Spaces
|
| 15 |
+
demo.queue()
|
| 16 |
|
| 17 |
+
if __name__ == "__main__":
|
| 18 |
+
# We use share=False because Spaces already handles public URL.
|
| 19 |
+
demo.launch(mcp_server=True, share=False)
|
|
|
|
|
|
|
|
|
|
|
|