File size: 1,597 Bytes
eacbbc9 e2dbb45 eacbbc9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
"""
Configuration settings for the application
"""
import os
from pydantic_settings import BaseSettings
from dotenv import load_dotenv
from pathlib import Path
# Load .env file if it exists
load_dotenv()
class Settings(BaseSettings):
"""Application settings"""
# App settings
APP_NAME: str = "VizWiz VQA API"
DEBUG: bool = os.getenv("DEBUG", "False").lower() == "true"
# Model settings
MODEL_PATH: str = os.getenv("MODEL_PATH", "./models/vqa_model_best.pt")
TEXT_MODEL: str = os.getenv("TEXT_MODEL", "bert-base-uncased")
VISION_MODEL: str = os.getenv("VISION_MODEL", "google/vit-base-patch16-384")
HUGGINGFACE_TOKEN: str = os.getenv("HUGGINGFACE_TOKEN", "")
# Hugging Face model repository settings
HF_MODEL_REPO: str = os.getenv("HF_MODEL_REPO", "dixisouls/VQA")
HF_MODEL_FILENAME: str = os.getenv("HF_MODEL_FILENAME", "model.pt")
# API settings
MAX_UPLOAD_SIZE: int = 10 * 1024 * 1024 # 10MB
# Storage settings
UPLOAD_DIR: str = os.getenv("UPLOAD_DIR", "./uploads")
MAX_SESSION_AGE: int = 60 * 30 # 30 minutes
# CORS settings
ALLOW_ORIGINS: list[str] = ["*"]
# Hugging Face Spaces specific settings
PORT: int = int(os.getenv("PORT", "7860"))
class Config:
env_file = ".env"
case_sensitive = True
# Global settings instance
settings = Settings()
# Ensure upload directory exists
Path(settings.UPLOAD_DIR).mkdir(parents=True, exist_ok=True)
# Ensure models directory exists
Path(os.path.dirname(settings.MODEL_PATH)).mkdir(parents=True, exist_ok=True) |