Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,17 @@
|
|
1 |
import asyncio
|
2 |
import websockets
|
3 |
-
from transformers import pipeline
|
4 |
|
5 |
-
|
6 |
-
nlp = pipeline("sentiment-analysis")
|
7 |
|
8 |
-
async def
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
|
15 |
-
|
16 |
-
start_server = websockets.serve(handle_client, "localhost", 8765)
|
17 |
|
18 |
asyncio.get_event_loop().run_until_complete(start_server)
|
19 |
-
asyncio.get_event_loop().run_forever()
|
|
|
1 |
import asyncio
|
2 |
import websockets
|
|
|
3 |
|
4 |
+
clients = set()
|
|
|
5 |
|
6 |
+
async def chat_server(websocket, path):
|
7 |
+
clients.add(websocket)
|
8 |
+
try:
|
9 |
+
async for message in websocket:
|
10 |
+
await asyncio.wait([client.send(message) for client in clients if client != websocket])
|
11 |
+
finally:
|
12 |
+
clients.remove(websocket)
|
13 |
|
14 |
+
start_server = websockets.serve(chat_server, "localhost", 7860)
|
|
|
15 |
|
16 |
asyncio.get_event_loop().run_until_complete(start_server)
|
17 |
+
asyncio.get_event_loop().run_forever()
|