Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,15 +16,16 @@ def chat(message, history):
|
|
| 16 |
client = sseclient.SSEClient(response)
|
| 17 |
|
| 18 |
output = ""
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
yield [{"role": "assistant", "content": f"Error: {e}"}]
|
| 27 |
|
| 28 |
-
# Launch with type="messages" to use the new message format
|
| 29 |
gr.ChatInterface(fn=chat, title="Sentiment Tiny Agent", type="messages").launch(share=True)
|
| 30 |
-
|
|
|
|
| 16 |
client = sseclient.SSEClient(response)
|
| 17 |
|
| 18 |
output = ""
|
| 19 |
+
try:
|
| 20 |
+
for event in client.events():
|
| 21 |
+
if event.data == "[DONE]":
|
| 22 |
+
break
|
| 23 |
+
output += event.data
|
| 24 |
+
yield [{"role": "assistant", "content": output}]
|
| 25 |
+
except (StopIteration, StopAsyncIteration):
|
| 26 |
+
# Graceful end of generator
|
| 27 |
+
return
|
| 28 |
except Exception as e:
|
| 29 |
yield [{"role": "assistant", "content": f"Error: {e}"}]
|
| 30 |
|
|
|
|
| 31 |
gr.ChatInterface(fn=chat, title="Sentiment Tiny Agent", type="messages").launch(share=True)
|
|
|