Project Files
src / fastvlm_server / config.py
"""Configuration management for FastVLM Server."""
from __future__ import annotations
import os
from dataclasses import dataclass, field
from pathlib import Path
from typing import Literal
@dataclass
class ServerConfig:
port: int = 8765
host: str = "127.0.0.1"
model_path: str = ""
log_level: Literal["debug", "info", "warn", "error"] = "info"
backend: Literal["ane", "mlx"] = "ane"
pid_file: str = field(default_factory=lambda: str(Path.home() / ".fastvlm" / "fastvlm.pid"))
log_file: str = field(default_factory=lambda: str(Path.home() / ".fastvlm" / "fastvlm.log"))
max_tokens: int = 256
temperature: float = 0.7
florence2_model_path: str = ""
lazy: bool = False
detect_backend: str = "florence2"
qwen3_vl_model_path: str = ""
def __post_init__(self):
self.model_path = os.path.expanduser(self.model_path)
self.pid_file = os.path.expanduser(self.pid_file)
self.log_file = os.path.expanduser(self.log_file)
if self.florence2_model_path:
self.florence2_model_path = os.path.expanduser(self.florence2_model_path)
if self.qwen3_vl_model_path:
self.qwen3_vl_model_path = os.path.expanduser(self.qwen3_vl_model_path)
Path(self.pid_file).parent.mkdir(parents=True, exist_ok=True)
Path(self.log_file).parent.mkdir(parents=True, exist_ok=True)
@property
def resolved_backend(self) -> str:
"""Resolved backend selected by user (no implicit fallback)."""
return self.backend
_config: ServerConfig | None = None
def get_config() -> ServerConfig:
global _config
if _config is None:
_config = ServerConfig()
return _config
def set_config(config: ServerConfig) -> None:
global _config
_config = config