Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import sseclient
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def chat(message, history):
|
| 6 |
url = "https://wlchee-mcp-sentiment.hf.space/gradio_api/mcp/sse"
|
|
@@ -8,11 +11,10 @@ def chat(message, history):
|
|
| 8 |
"Accept": "text/event-stream",
|
| 9 |
"Content-Type": "application/json"
|
| 10 |
}
|
| 11 |
-
payload = {"input": message}
|
| 12 |
|
| 13 |
try:
|
| 14 |
-
|
| 15 |
-
response = requests.post(url, json=payload, headers=headers, stream=True)
|
| 16 |
client = sseclient.SSEClient(response)
|
| 17 |
|
| 18 |
output = ""
|
|
@@ -25,4 +27,4 @@ def chat(message, history):
|
|
| 25 |
yield f"Error: {e}"
|
| 26 |
|
| 27 |
# Launch Tiny Agent UI
|
| 28 |
-
gr.ChatInterface(fn=chat, title="Sentiment Tiny Agent").launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import sseclient
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
# Corrected streaming function for Tiny Agent
|
| 7 |
|
| 8 |
def chat(message, history):
|
| 9 |
url = "https://wlchee-mcp-sentiment.hf.space/gradio_api/mcp/sse"
|
|
|
|
| 11 |
"Accept": "text/event-stream",
|
| 12 |
"Content-Type": "application/json"
|
| 13 |
}
|
| 14 |
+
payload = json.dumps({"input": message})
|
| 15 |
|
| 16 |
try:
|
| 17 |
+
response = requests.post(url, data=payload, headers=headers, stream=True)
|
|
|
|
| 18 |
client = sseclient.SSEClient(response)
|
| 19 |
|
| 20 |
output = ""
|
|
|
|
| 27 |
yield f"Error: {e}"
|
| 28 |
|
| 29 |
# Launch Tiny Agent UI
|
| 30 |
+
gr.ChatInterface(fn=chat, title="Sentiment Tiny Agent").launch(mcp_server=True)
|