|
|
import os |
|
|
from dataclasses import dataclass |
|
|
|
|
|
|
|
|
@dataclass |
|
|
class Config: |
|
|
api_key: str |
|
|
model_path: str |
|
|
|
|
|
vl_model_path: str |
|
|
|
|
|
vl_api_base: str |
|
|
vl_api_key: str |
|
|
vl_api_model: str |
|
|
vl_use_api: bool |
|
|
|
|
|
vl_api_max_calls: int |
|
|
|
|
|
vl_always_load_local: bool |
|
|
|
|
|
host: str |
|
|
port: int |
|
|
gradio_port: int |
|
|
device: str |
|
|
|
|
|
|
|
|
def load_config() -> Config: |
|
|
return Config( |
|
|
api_key=os.getenv("XGUARD_API_KEY", "your-api-key"), |
|
|
model_path=os.getenv("XGUARD_MODEL_PATH", "Alibaba-AAIG/YuFeng-XGuard-Reason-0.6B"), |
|
|
vl_model_path=os.getenv("XGUARD_VL_MODEL_PATH","Qwen/Qwen3-VL-2B-Instruct"), |
|
|
vl_api_base=os.getenv("XGUARD_VL_API_BASE", "https://dashscope.aliyuncs.com/compatible-mode/v1"), |
|
|
vl_api_key=os.getenv("XGUARD_VL_API_KEY", ""), |
|
|
vl_api_model=os.getenv("XGUARD_VL_API_MODEL", "qwen-vl-max-latest"), |
|
|
vl_use_api=os.getenv("XGUARD_VL_USE_API", "false").lower() in ("true", "1", "yes"), |
|
|
vl_api_max_calls=int(os.getenv("XGUARD_VL_API_MAX_CALLS", "")), |
|
|
vl_always_load_local=os.getenv("XGUARD_VL_ALWAYS_LOAD_LOCAL", "true").lower() in ("true", "1", "yes"), |
|
|
host=os.getenv("XGUARD_HOST", "0.0.0.0"), |
|
|
port=int(os.getenv("XGUARD_PORT", "8080")), |
|
|
gradio_port=int(os.getenv("XGUARD_GRADIO_PORT", "7860")), |
|
|
device=os.getenv("XGUARD_DEVICE", "auto"), |
|
|
) |
|
|
|