wlchee commited on
Commit
22f14e8
·
verified ·
1 Parent(s): 4d9635d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import requests
3
  import sseclient
4
 
5
- def stream_response(prompt):
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
- # Make a streaming request
15
- response = requests.post(url, json=payload, stream=True, headers=headers)
16
  client = sseclient.SSEClient(response)
17
 
18
- full_output = ""
19
  for event in client.events():
20
  if event.data == "[DONE]":
21
  break
22
- full_output += event.data
23
- yield full_output # Gradio can stream this in real-time
24
  except Exception as e:
25
  yield f"Error: {e}"
26
 
27
- demo = gr.Interface(fn=stream_response, inputs="text", outputs="text", live=True)
28
- demo.launch()
 
 
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
+