Files
infinifi/inference_server.py
Kenneth a6d6487df3 fix: websocket issue
websocket.create_connection is short lived, so whenever the inference
server is needed, it needs to be called again to reconnect to the
server.
2024-07-23 21:43:35 +01:00

31 lines
627 B
Python

import asyncio
from websockets.server import serve
from generate import generate
async def handler(websocket):
async for message in websocket:
if message != "generate":
continue
print("generating new audio clips...")
generate()
print("audio generated")
for i in range(5):
with open(f"{i}.mp3", "rb") as f:
data = f.read()
await websocket.send(data)
async def main():
async with serve(handler, "localhost", 8001, ping_interval=5):
await asyncio.Future()
if __name__ == "__main__":
asyncio.run(main())