|
import os |
|
from typing import Optional |
|
|
|
class Config: |
|
"""Application configuration for working with local GGUF models""" |
|
|
|
|
|
MODEL_REPO: str = os.getenv("MODEL_REPO", "lmstudio-community/gemma-3n-E4B-it-text-GGUF") |
|
MODEL_FILENAME: str = os.getenv("MODEL_FILENAME", "gemma-3n-E4B-it-Q8_0.gguf") |
|
MODEL_PATH: str = os.getenv("MODEL_PATH", "/app/models/gemma-3n-E4B-it-Q8_0.gguf") |
|
HUGGINGFACE_TOKEN: str = os.getenv("HUGGINGFACE_TOKEN", "") |
|
|
|
|
|
N_CTX: int = int(os.getenv("N_CTX", "4096")) |
|
N_GPU_LAYERS: int = int(os.getenv("N_GPU_LAYERS", "0")) |
|
N_THREADS: int = int(os.getenv("N_THREADS", "4")) |
|
N_BATCH: int = int(os.getenv("N_BATCH", "512")) |
|
USE_MLOCK: bool = os.getenv("USE_MLOCK", "false").lower() == "true" |
|
USE_MMAP: bool = os.getenv("USE_MMAP", "true").lower() == "true" |
|
F16_KV: bool = os.getenv("F16_KV", "true").lower() == "true" |
|
SEED: int = int(os.getenv("SEED", "42")) |
|
|
|
|
|
HOST: str = os.getenv("HOST", "0.0.0.0") |
|
GRADIO_PORT: int = int(os.getenv("GRADIO_PORT", "7860")) |
|
API_PORT: int = int(os.getenv("API_PORT", "8000")) |
|
|
|
|
|
MAX_NEW_TOKENS: int = int(os.getenv("MAX_NEW_TOKENS", "256")) |
|
TEMPERATURE: float = float(os.getenv("TEMPERATURE", "0.1")) |
|
|
|
|
|
MAX_FILE_SIZE: int = int(os.getenv("MAX_FILE_SIZE", "10485760")) |
|
ALLOWED_IMAGE_EXTENSIONS: set = {".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp"} |
|
|
|
@classmethod |
|
def is_model_available(cls) -> bool: |
|
"""Check if local model file exists""" |
|
return os.path.exists(cls.MODEL_PATH) |
|
|
|
@classmethod |
|
def get_model_path(cls) -> str: |
|
"""Get absolute path to model file""" |
|
return os.path.abspath(cls.MODEL_PATH) |
|
|
|
@classmethod |
|
def get_models_dir(cls) -> str: |
|
"""Get models directory path""" |
|
return os.path.dirname(cls.MODEL_PATH) |
|
|
|
@classmethod |
|
def load_from_env_file(cls, env_file: str = ".env") -> None: |
|
"""Load configuration from .env file""" |
|
if os.path.exists(env_file): |
|
with open(env_file, 'r') as f: |
|
for line in f: |
|
line = line.strip() |
|
if line and not line.startswith('#') and '=' in line: |
|
key, value = line.split('=', 1) |
|
os.environ[key.strip()] = value.strip() |
|
|
|
|
|
Config.load_from_env_file() |
|
|