Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import sseclient
|
| 4 |
|
| 5 |
-
def
|
| 6 |
url = "https://wlchee-mcp-sentiment.hf.space/gradio_api/mcp/sse"
|
| 7 |
headers = {
|
| 8 |
"Accept": "text/event-stream",
|
|
@@ -11,18 +11,19 @@ def stream_response(prompt):
|
|
| 11 |
payload = {"input": prompt}
|
| 12 |
|
| 13 |
try:
|
| 14 |
-
#
|
| 15 |
-
response = requests.post(url, json=payload,
|
| 16 |
client = sseclient.SSEClient(response)
|
| 17 |
|
| 18 |
-
|
| 19 |
for event in client.events():
|
| 20 |
if event.data == "[DONE]":
|
| 21 |
break
|
| 22 |
-
|
| 23 |
-
yield
|
| 24 |
except Exception as e:
|
| 25 |
yield f"Error: {e}"
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
| 2 |
import requests
|
| 3 |
import sseclient
|
| 4 |
|
| 5 |
+
def chat(prompt):
|
| 6 |
url = "https://wlchee-mcp-sentiment.hf.space/gradio_api/mcp/sse"
|
| 7 |
headers = {
|
| 8 |
"Accept": "text/event-stream",
|
|
|
|
| 11 |
payload = {"input": prompt}
|
| 12 |
|
| 13 |
try:
|
| 14 |
+
# Send streaming request to MCP server
|
| 15 |
+
response = requests.post(url, json=payload, headers=headers, stream=True)
|
| 16 |
client = sseclient.SSEClient(response)
|
| 17 |
|
| 18 |
+
output = ""
|
| 19 |
for event in client.events():
|
| 20 |
if event.data == "[DONE]":
|
| 21 |
break
|
| 22 |
+
output += event.data
|
| 23 |
+
yield output
|
| 24 |
except Exception as e:
|
| 25 |
yield f"Error: {e}"
|
| 26 |
|
| 27 |
+
# Launch Tiny Agent UI
|
| 28 |
+
gr.ChatInterface(chat, title="Sentiment Tiny Agent").launch()
|
| 29 |
+
|