tiny-agent / app.py
wlchee's picture
Update app.py
f1431ce verified
raw
history blame
820 Bytes
import gradio as gr
import requests
import sseclient
import json
# Corrected streaming function for Tiny Agent
def chat(message, history):
url = "https://wlchee-mcp-sentiment.hf.space/gradio_api/mcp/sse"
headers = {
"Accept": "text/event-stream",
"Content-Type": "application/json"
}
payload = json.dumps({"input": message})
try:
response = requests.post(url, data=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()