File size: 840 Bytes
4558342
 
 
cc7b83d
 
 
4558342
22f14e8
4558342
 
 
 
 
 
 
 
22f14e8
 
4558342
 
22f14e8
4558342
 
 
22f14e8
 
4558342
 
 
22f14e8
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()