|
""" |
|
應用配置檔案 |
|
""" |
|
import os |
|
from pathlib import Path |
|
|
|
|
|
BASE_DIR = Path(__file__).parent.parent |
|
MODELS_DIR = BASE_DIR / "models" |
|
RESULTS_DIR = BASE_DIR / "results" |
|
|
|
|
|
MODEL_CONFIG = { |
|
"FACE_ANALYSIS_MODEL": "buffalo_l", |
|
"FACE_SWAP_MODEL": "inswapper_128.onnx", |
|
"DETECTION_SIZE": (640, 640), |
|
"CTX_ID": 0, |
|
} |
|
|
|
|
|
TEMPLATE_CONFIG = { |
|
"TEMPLATES": { |
|
"1": { |
|
"id": "1", |
|
"name": "模板 1", |
|
"description": "預設模板", |
|
"path": "./models/templates/step01.jpg" |
|
}, |
|
"2": { |
|
"id": "2", |
|
"name": "模板 2", |
|
"description": "預設模板", |
|
"path": "./models/templates/step02.jpg" |
|
}, |
|
"3": { |
|
"id": "3", |
|
"name": "模板 3", |
|
"description": "預設模板", |
|
"path": "./models/templates/step03.jpg" |
|
}, |
|
"4": { |
|
"id": "4", |
|
"name": "模板 4", |
|
"description": "預設模板", |
|
"path": "./models/templates/step04.jpg" |
|
}, |
|
"5": { |
|
"id": "5", |
|
"name": "模板 5", |
|
"description": "預設模板", |
|
"path": "./models/templates/step05.jpg" |
|
}, |
|
"6": { |
|
"id": "6", |
|
"name": "模板 6", |
|
"description": "預設模板", |
|
"path": "./models/templates/step06.jpg" |
|
} |
|
} |
|
} |
|
|
|
def get_model_path(model_name: str) -> Path: |
|
"""獲取模型檔案路徑""" |
|
|
|
local_model_path = MODELS_DIR / model_name |
|
if local_model_path.exists(): |
|
return local_model_path |
|
|
|
return local_model_path |
|
|
|
def get_template_path(template_id: str) -> Path: |
|
"""獲取模板圖片路徑""" |
|
template = TEMPLATE_CONFIG["TEMPLATES"].get(template_id) |
|
if not template: |
|
raise ValueError(f"Template {template_id} not found") |
|
|
|
template_path = template["path"] |
|
|
|
if template_path.startswith("./"): |
|
return BASE_DIR / template_path[2:] |
|
return Path(template_path) |
|
|
|
def ensure_directories(): |
|
"""確保必要的目錄存在""" |
|
|
|
(MODELS_DIR / "templates").mkdir(parents=True, exist_ok=True) |
|
|
|
|