clone3 commited on
Commit
eabc2af
·
verified ·
1 Parent(s): 2af63db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -1,19 +1,17 @@
1
  import asyncio
2
  import websockets
3
- from transformers import pipeline
4
 
5
- # Load a Hugging Face model
6
- nlp = pipeline("sentiment-analysis")
7
 
8
- async def handle_client(websocket, path):
9
- async for message in websocket:
10
- # Process the message using the Hugging Face model
11
- result = nlp(message)
12
- # Send the result back to the client
13
- await websocket.send(str(result))
 
14
 
15
- # Start the WebSocket server
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()