blizzarman/polyglot-tutor
0
1"""Centralised, environment-driven configuration.2 3Every provider choice (LLM, ASR, TTS, storage) is a plain env var so the same4image runs as the free HF Space ("light" mode) or against the local GPU box5("premium" mode) without code changes.6 7The `Literal` types are intentionally restricted to *implemented* providers:8adding an implementation means widening the Literal, so the config can never9silently point at a backend that does not exist yet.10"""11 12from functools import lru_cache13from typing import Literal14 15from pydantic import SecretStr16from pydantic_settings import BaseSettings, SettingsConfigDict17 18 19class Settings(BaseSettings):20 model_config = SettingsConfigDict(21 env_file=".env",22 env_file_encoding="utf-8",23 extra="ignore",24 )25 26 # --- App ---27 app_env: Literal["dev", "prod"] = "dev"28 log_level: str = "INFO"29 30 # --- Languages ---31 default_source_lang: str = "fr"32 default_target_lang: str = "en"33 34 # --- LLM ---35 llm_provider: Literal["fake", "gemini", "openai", "mistral", "ollama"] = "fake"36 llm_model: str = "gemini-2.5-flash"37 llm_api_key: SecretStr | None = None38 llm_base_url: str | None = None39 llm_timeout_s: float = 30.040 41 # --- CEFR classifier (M1) ---42 cefr_model_path: str | None = None # local ONNX artifact dir (dev) — takes precedence43 cefr_model_id: str | None = None # HF model repo id (Space; HF_TOKEN env for private repos)44 cache_dir: str = ".cache/tutor" # content-addressed cache for LLM products45 46 # --- ASR (M2) / TTS / storage ---47 asr_provider: Literal["fake", "faster_whisper"] = "fake"48 asr_model: str = "small" # faster-whisper size; see docs/evals/m2_asr_latency.md49 asr_compute_type: str = "int8"50 asr_cpu_threads: int = 251 tts_provider: Literal["fake"] = "fake" # M2 TTS is browser-side (Web Speech API)52 storage_backend: Literal["memory"] = "memory"53 54 # --- Gradio ---55 host: str = "0.0.0.0"56 port: int = 786057 gradio_auth_username: str | None = None58 gradio_auth_password: SecretStr | None = None59 60 61@lru_cache62def get_settings() -> Settings:63 """Process-wide settings singleton (tests build `Settings` directly instead)."""64 return Settings()65 