tiny-agent / app.py
wlchee's picture
Update app.py
e68bd3a verified
raw
history blame
794 Bytes
import gradio as gr
import requests
import sseclient
def chat(message, history):
url = "https://alan-mcp-sentiment.hf.space/gradio_api/mcp/sse"
headers = {
"Accept": "text/event-stream",
"Content-Type": "application/json"
}
payload = {"input": message}
try:
# Send streaming request to MCP server
response = requests.post(url, json=payload, headers=headers, stream=True)
client = sseclient.SSEClient(response)
output = ""
for event in client.events():
if event.data == "[DONE]":
break
output += event.data
yield output
except Exception as e:
yield f"Error: {e}"
# Launch Tiny Agent UI
gr.ChatInterface(fn=chat, title="Sentiment Tiny Agent").launch()