feat: allow user to customize services' ports; updated README.md
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
from pathlib import Path
|
||||
@@ -41,6 +42,8 @@ class ModelManager:
|
||||
self.active_model: Optional[str] = None
|
||||
self._lock = asyncio.Lock()
|
||||
self._process: Optional[subprocess.Popen] = None
|
||||
self.acestep_port: int = ACESTEP_PORT
|
||||
self.foundation1_port: int = FOUNDATION1_PORT
|
||||
|
||||
async def load(self, model: str) -> None:
|
||||
"""Load a model, unloading the currently active one first if needed."""
|
||||
@@ -83,10 +86,10 @@ class ModelManager:
|
||||
def _start_process(self, model: str) -> None:
|
||||
if model == "fullsong":
|
||||
self._process = self._launch_acestep()
|
||||
self._wait_healthy(f"http://127.0.0.1:{ACESTEP_PORT}/health")
|
||||
self._wait_healthy(f"http://127.0.0.1:{self.acestep_port}/health")
|
||||
elif model == "clip":
|
||||
self._process = self._launch_foundation1()
|
||||
self._wait_healthy(f"http://127.0.0.1:{FOUNDATION1_PORT}/health")
|
||||
self._wait_healthy(f"http://127.0.0.1:{self.foundation1_port}/health")
|
||||
elif model == "separator":
|
||||
pass # no persistent process; previous model already stopped by load(), VRAM is free
|
||||
else:
|
||||
@@ -95,15 +98,17 @@ class ModelManager:
|
||||
def _launch_acestep(self) -> subprocess.Popen:
|
||||
venv_python = _python_exe(ROOT_DIR / "ace-step" / ".venv")
|
||||
cmd = [str(venv_python), "-c", "from acestep.api_server import main; main()"]
|
||||
logger.info("Launching ACE-Step: %s", " ".join(cmd))
|
||||
return subprocess.Popen(cmd, cwd=str(ROOT_DIR / "ace-step"))
|
||||
env = {**os.environ, "ACESTEP_API_PORT": str(self.acestep_port)}
|
||||
logger.info("Launching ACE-Step on port %d: %s", self.acestep_port, " ".join(cmd))
|
||||
return subprocess.Popen(cmd, cwd=str(ROOT_DIR / "ace-step"), env=env)
|
||||
|
||||
def _launch_foundation1(self) -> subprocess.Popen:
|
||||
venv_python = _python_exe(ROOT_DIR / "foundation1" / ".venv")
|
||||
server_script = str(ROOT_DIR / "foundation1_server" / "server.py")
|
||||
cmd = [str(venv_python), server_script]
|
||||
logger.info("Launching Foundation-1 server: %s", " ".join(cmd))
|
||||
return subprocess.Popen(cmd, cwd=str(ROOT_DIR))
|
||||
env = {**os.environ, "FOUNDATION1_SERVER_PORT": str(self.foundation1_port)}
|
||||
logger.info("Launching Foundation-1 server on port %d: %s", self.foundation1_port, " ".join(cmd))
|
||||
return subprocess.Popen(cmd, cwd=str(ROOT_DIR), env=env)
|
||||
|
||||
def _wait_healthy(self, url: str) -> None:
|
||||
deadline = time.monotonic() + HEALTH_TIMEOUT_SECONDS
|
||||
|
||||
Reference in New Issue
Block a user