Files
infinifi/inference_server.py

32 lines
635 B
Python
Raw Normal View History

2024-07-22 22:24:39 +01:00
import asyncio
from websockets.server import serve
2024-07-22 22:38:31 +01:00
from generate import generate
2024-07-24 17:32:46 +01:00
from logger import log_info
2024-07-22 22:24:39 +01:00
async def handler(websocket):
async for message in websocket:
if message != "generate":
continue
2024-07-24 17:32:46 +01:00
log_info("generating new audio clips...")
2024-07-22 22:24:39 +01:00
2024-07-22 22:38:31 +01:00
generate()
2024-07-22 22:24:39 +01:00
2024-07-24 17:32:46 +01:00
log_info("audio generated")
2024-07-22 22:24:39 +01:00
for i in range(5):
2024-07-22 22:38:31 +01:00
with open(f"{i}.mp3", "rb") as f:
2024-07-22 22:24:39 +01:00
data = f.read()
await websocket.send(data)
async def main():
async with serve(handler, "", 8001):
2024-07-22 22:24:39 +01:00
await asyncio.Future()
if __name__ == "__main__":
asyncio.run(main())