Spaces:
Running
on
A100
Running
on
A100
feat: api result return download url
Browse files- acestep/api_server.py +16 -3
acestep/api_server.py
CHANGED
|
@@ -276,6 +276,19 @@ def create_app() -> FastAPI:
|
|
| 276 |
INITIAL_AVG_JOB_SECONDS = float(os.getenv("ACESTEP_AVG_JOB_SECONDS", "5.0"))
|
| 277 |
AVG_WINDOW = int(os.getenv("ACESTEP_AVG_WINDOW", "50"))
|
| 278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
@asynccontextmanager
|
| 280 |
async def lifespan(app: FastAPI):
|
| 281 |
# Clear proxy env that may affect downstream libs
|
|
@@ -732,9 +745,9 @@ def create_app() -> FastAPI:
|
|
| 732 |
progress=None,
|
| 733 |
)
|
| 734 |
return {
|
| 735 |
-
"first_audio_path": first,
|
| 736 |
-
"second_audio_path": second,
|
| 737 |
-
"audio_paths": paths,
|
| 738 |
"generation_info": gen_info,
|
| 739 |
"status_message": status_msg,
|
| 740 |
"seed_value": seed_value,
|
|
|
|
| 276 |
INITIAL_AVG_JOB_SECONDS = float(os.getenv("ACESTEP_AVG_JOB_SECONDS", "5.0"))
|
| 277 |
AVG_WINDOW = int(os.getenv("ACESTEP_AVG_WINDOW", "50"))
|
| 278 |
|
| 279 |
+
# 服务器配置,用于生成音频下载 URL
|
| 280 |
+
SERVER_HOST = os.getenv("ACESTEP_API_HOST", "127.0.0.1")
|
| 281 |
+
SERVER_PORT = int(os.getenv("ACESTEP_API_PORT", "8001"))
|
| 282 |
+
|
| 283 |
+
def _path_to_audio_url(path: str) -> str:
|
| 284 |
+
"""将本地文件路径转换为可下载的 HTTP URL"""
|
| 285 |
+
if not path:
|
| 286 |
+
return path
|
| 287 |
+
if path.startswith("http://") or path.startswith("https://"):
|
| 288 |
+
return path
|
| 289 |
+
encoded_path = urllib.parse.quote(path, safe="")
|
| 290 |
+
return f"http://{SERVER_HOST}:{SERVER_PORT}/v1/audio?path={encoded_path}"
|
| 291 |
+
|
| 292 |
@asynccontextmanager
|
| 293 |
async def lifespan(app: FastAPI):
|
| 294 |
# Clear proxy env that may affect downstream libs
|
|
|
|
| 745 |
progress=None,
|
| 746 |
)
|
| 747 |
return {
|
| 748 |
+
"first_audio_path": _path_to_audio_url(first) if first else None,
|
| 749 |
+
"second_audio_path": _path_to_audio_url(second) if second else None,
|
| 750 |
+
"audio_paths": [_path_to_audio_url(p) for p in (paths or [])],
|
| 751 |
"generation_info": gen_info,
|
| 752 |
"status_message": status_msg,
|
| 753 |
"seed_value": seed_value,
|