Initial commit: ASR v2 with multi-venv isolation
- faster-whisper, Qwen3-ASR, gateway 각 컴포넌트별 Python venv 분리 - 기본언어 한국어(ko) - 처리내역 탭: 목록/상세/원본파일 재생/삭제 - 백엔드별 동적 모델 드랍다운 - /history, /uploads API 추가 - 기존 인스턴스(port 18100) 보존, 신규 port 18101 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
65
app/common.py
Normal file
65
app/common.py
Normal file
@@ -0,0 +1,65 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
|
||||
def env_str(name: str, default: str = "") -> str:
|
||||
return os.getenv(name, default)
|
||||
|
||||
|
||||
def env_int(name: str, default: int) -> int:
|
||||
raw = os.getenv(name)
|
||||
if raw is None or raw == "":
|
||||
return default
|
||||
return int(raw)
|
||||
|
||||
|
||||
def env_float(name: str, default: float) -> float:
|
||||
raw = os.getenv(name)
|
||||
if raw is None or raw == "":
|
||||
return default
|
||||
return float(raw)
|
||||
|
||||
|
||||
def env_bool(name: str, default: bool = False) -> bool:
|
||||
raw = os.getenv(name)
|
||||
if raw is None:
|
||||
return default
|
||||
return raw.strip().lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
ASR_BASE_DIR = Path(env_str("ASR_BASE_DIR", "/srv/asr"))
|
||||
MODEL_CACHE = Path(env_str("WHISPER_CACHE_DIR", str(ASR_BASE_DIR / "models-cache")))
|
||||
UPLOAD_DIR = ASR_BASE_DIR / "uploads"
|
||||
RESULT_DIR = ASR_BASE_DIR / "results"
|
||||
CUSTOM_MODEL_DIR = ASR_BASE_DIR / "custom-models"
|
||||
|
||||
DEVICE = env_str("ASR_DEVICE", "cuda")
|
||||
COMPUTE_TYPE = env_str("ASR_COMPUTE_TYPE", "float16")
|
||||
DEFAULT_BACKEND = env_str("DEFAULT_BACKEND", "faster-whisper")
|
||||
DEFAULT_MODEL = env_str("DEFAULT_MODEL", "large-v3")
|
||||
DEFAULT_LANGUAGE = env_str("DEFAULT_LANGUAGE", "ko")
|
||||
|
||||
FASTER_WHISPER_URL = env_str("FASTER_WHISPER_URL", "http://127.0.0.1:8001")
|
||||
QWEN3_URL = env_str("QWEN3_URL", "http://127.0.0.1:8004")
|
||||
|
||||
PYANNOTE_HF_TOKEN = env_str("PYANNOTE_HF_TOKEN", "")
|
||||
|
||||
|
||||
def ensure_runtime_dirs() -> None:
|
||||
for p in [ASR_BASE_DIR, MODEL_CACHE, UPLOAD_DIR, RESULT_DIR, CUSTOM_MODEL_DIR]:
|
||||
p.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
def resolve_custom_model_path(custom_model_path: Optional[str]) -> Optional[str]:
|
||||
if not custom_model_path:
|
||||
return None
|
||||
raw = custom_model_path.strip()
|
||||
if not raw:
|
||||
return None
|
||||
candidate = Path(raw)
|
||||
if candidate.is_absolute():
|
||||
return str(candidate)
|
||||
return str((CUSTOM_MODEL_DIR / candidate).resolve())
|
||||
Reference in New Issue
Block a user