tiny-agent / app.py
wlchee's picture
Update app.py
cc7b83d verified
raw
history blame
840 Bytes
import gradio as gr
import requests
import sseclient
import logging
logging.basicConfig(level=logging.DEBUG)
def chat(prompt):
url = "https://wlchee-mcp-sentiment.hf.space/gradio_api/mcp/sse"
headers = {
"Accept": "text/event-stream",
"Content-Type": "application/json"
}
payload = {"input": prompt}
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(chat, title="Sentiment Tiny Agent").launch()