Salman Abjam
Initial deployment: DeepVision Prompt Builder v0.1.0
eb5a9e1
"""
Configuration module for DeepVision Core Engine.
Manages all configuration settings including paths, model settings,
processing parameters, and resource limits.
"""
import os
from pathlib import Path
from typing import Dict, List, Optional
from pydantic_settings import BaseSettings
from pydantic import Field
class CoreConfig(BaseSettings):
"""Core configuration settings."""
# Application
APP_NAME: str = "DeepVision Prompt Builder"
APP_VERSION: str = "0.1.0"
DEBUG: bool = Field(default=False, env="DEBUG")
# Paths
BASE_DIR: Path = Path(__file__).parent.parent
UPLOAD_DIR: Path = Field(default=Path("/var/uploads"), env="UPLOAD_DIR")
CACHE_DIR: Path = Field(default=Path("/var/cache"), env="CACHE_DIR")
MODEL_DIR: Path = Field(default=Path("models"), env="MODEL_DIR")
# File Processing
MAX_IMAGE_SIZE: int = Field(default=50 * 1024 * 1024, env="MAX_IMAGE_SIZE") # 50MB
MAX_VIDEO_SIZE: int = Field(default=200 * 1024 * 1024, env="MAX_VIDEO_SIZE") # 200MB
ALLOWED_IMAGE_FORMATS: List[str] = [".jpg", ".jpeg", ".png", ".gif", ".webp"]
ALLOWED_VIDEO_FORMATS: List[str] = [".mp4", ".mov", ".avi"]
# Image Processing
IMAGE_MAX_DIMENSION: int = 2048 # Max width or height
IMAGE_QUALITY: int = 85 # JPEG quality
DEFAULT_IMAGE_SIZE: tuple = (512, 512) # Default resize
# Video Processing
VIDEO_FPS_EXTRACTION: int = 1 # Extract 1 frame per second
MAX_FRAMES_PER_VIDEO: int = 100 # Maximum frames to extract
# Model Settings
DEVICE: str = Field(default="cpu", env="DEVICE") # cpu or cuda
MODEL_BATCH_SIZE: int = 4
MODEL_CACHE_SIZE: int = 3 # Max models in memory
# Performance
MAX_WORKERS: int = Field(default=4, env="MAX_WORKERS")
ENABLE_CACHING: bool = True
CACHE_TTL: int = 3600 # Cache time-to-live in seconds
# Output
OUTPUT_FORMAT: str = "json" # json, dict
PRETTY_JSON: bool = True
INCLUDE_METADATA: bool = True
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
case_sensitive = True
def __init__(self, **kwargs):
super().__init__(**kwargs)
# Create directories if they don't exist
self.UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
self.CACHE_DIR.mkdir(parents=True, exist_ok=True)
self.MODEL_DIR.mkdir(parents=True, exist_ok=True)
# Global config instance
config = CoreConfig()
# Model configurations
MODEL_CONFIGS: Dict[str, Dict] = {
"clip": {
"name": "openai/clip-vit-base-patch32",
"task": "feature_extraction",
"device": config.DEVICE,
},
"blip2": {
"name": "Salesforce/blip2-opt-2.7b",
"task": "image_captioning",
"device": config.DEVICE,
},
"sam": {
"name": "facebook/sam-vit-base",
"task": "segmentation",
"device": config.DEVICE,
},
}
# Plugin configurations
PLUGIN_CONFIGS: Dict[str, Dict] = {
"object_detector": {
"enabled": True,
"model": "clip",
"confidence_threshold": 0.5,
},
"caption_generator": {
"enabled": True,
"model": "blip2",
"max_length": 50,
},
"color_analyzer": {
"enabled": True,
"num_colors": 5,
},
"text_extractor": {
"enabled": False, # Requires OCR model
"model": "easyocr",
},
"emotion_reader": {
"enabled": False, # Requires face detection model
"model": "deepface",
},
}
def get_plugin_config(plugin_name: str) -> Optional[Dict]:
"""Get configuration for a specific plugin."""
return PLUGIN_CONFIGS.get(plugin_name)
def is_plugin_enabled(plugin_name: str) -> bool:
"""Check if a plugin is enabled."""
plugin_config = get_plugin_config(plugin_name)
return plugin_config.get("enabled", False) if plugin_config else False