Spaces:
Sleeping
Sleeping
Download config.py from kajalan/hf-image-api: direct link, hf CLI and curl.
- Browser
- Download file 3 kB
-
https://huggingface.co/spaces/kajalan/hf-image-api/resolve/main/config.py
- Command line
-
hf download hf://spaces/kajalan/hf-image-api/config.py
-
curl -L -o config.py https://huggingface.co/spaces/kajalan/hf-image-api/resolve/main/config.py
3 kB
| """ | |
| config.py β All runtime settings loaded from environment / .env file. | |
| """ | |
| from pydantic_settings import BaseSettings | |
| from pydantic import Field | |
| import os | |
| class Settings(BaseSettings): | |
| # ββ Server ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| host: str = Field("0.0.0.0", env="HOST") | |
| port: int = Field(8000, env="PORT") | |
| debug: bool = Field(False, env="DEBUG") | |
| # ββ Model βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Best CPU models (small β fast): | |
| # "nota-ai/bk-sdm-small" (~500 MB, very fast on CPU) | |
| # "runwayml/stable-diffusion-v1-5" (~4 GB, standard quality) | |
| # "stabilityai/stable-diffusion-2-1-base" (~5 GB, higher quality) | |
| model_id: str = Field( | |
| "nota-ai/bk-sdm-small", | |
| env="MODEL_ID", | |
| ) | |
| model_cache_dir: str = Field("./model_cache", env="MODEL_CACHE_DIR") | |
| # Load the pipeline at startup (recommended β avoids cold-start on first job) | |
| auto_load_model: bool = Field(True, env="AUTO_LOAD_MODEL") | |
| # ββ CPU Optimisation ββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Number of CPU threads for PyTorch inference (0 = use all logical cores) | |
| cpu_threads: int = Field(0, env="CPU_THREADS") | |
| # Enable attention slicing (reduces peak RAM at slight speed cost) | |
| enable_attention_slicing: bool = Field(True, env="ENABLE_ATTENTION_SLICING") | |
| # Default inference steps (DPM++ scheduler works well at 20 steps on CPU) | |
| default_steps: int = Field(20, env="DEFAULT_STEPS") | |
| max_steps: int = Field(50, env="MAX_STEPS") | |
| # Default image dimensions (512Γ512 is ideal for SD v1.x on CPU) | |
| default_width: int = Field(512, env="DEFAULT_WIDTH") | |
| default_height: int = Field(512, env="DEFAULT_HEIGHT") | |
| max_width: int = Field(768, env="MAX_WIDTH") | |
| max_height: int = Field(768, env="MAX_HEIGHT") | |
| # Default guidance scale | |
| default_guidance_scale: float = Field(7.5, env="DEFAULT_GUIDANCE_SCALE") | |
| # ββ Storage βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| outputs_dir: str = Field("./outputs", env="OUTPUTS_DIR") | |
| # Auto-delete completed jobs after N seconds (0 = never) | |
| job_ttl_seconds: int = Field(0, env="JOB_TTL_SECONDS") | |
| class Config: | |
| env_file = ".env" | |
| env_file_encoding = "utf-8" | |
| settings = Settings() | |
| # Resolve absolute output path | |
| os.makedirs(settings.outputs_dir, exist_ok=True) | |
| os.makedirs(settings.model_cache_dir, exist_ok=True) | |