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.
This commit is contained in:
20
server.py
20
server.py
@@ -13,17 +13,16 @@ current_index = -1
|
||||
t = None
|
||||
# websocket connection to the inference server
|
||||
ws = None
|
||||
ws_url = ""
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
global ws
|
||||
global ws, ws_url
|
||||
|
||||
url = os.environ.get("INFERENCE_SERVER_WS_URL")
|
||||
if not url:
|
||||
url = "ws://localhost:8001"
|
||||
|
||||
ws = websocket.create_connection(url)
|
||||
print(f"websocket connected to {url}")
|
||||
ws_url = os.environ.get("INFERENCE_SERVER_WS_URL")
|
||||
if not ws_url:
|
||||
ws_url = "ws://localhost:8001"
|
||||
|
||||
advance()
|
||||
|
||||
@@ -36,7 +35,7 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
|
||||
def generate_new_audio():
|
||||
if not ws:
|
||||
if not ws_url:
|
||||
return
|
||||
|
||||
global current_index
|
||||
@@ -51,6 +50,9 @@ def generate_new_audio():
|
||||
|
||||
print("generating new audio...")
|
||||
|
||||
ws = websocket.create_connection(ws_url)
|
||||
print(f"websocket connected to {ws_url}")
|
||||
|
||||
ws.send("generate")
|
||||
|
||||
wavs = []
|
||||
@@ -66,6 +68,8 @@ def generate_new_audio():
|
||||
|
||||
print("audio generated.")
|
||||
|
||||
ws.close()
|
||||
|
||||
|
||||
def advance():
|
||||
global current_index, t
|
||||
|
Reference in New Issue
Block a user