wlchee commited on
Commit
f930515
·
verified ·
1 Parent(s): 9bc79ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -16,15 +16,16 @@ def chat(message, history):
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 as a list of message dicts in the new format
24
- yield [{"role": "assistant", "content": output}]
 
 
 
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)