Complete web interface for Meta's AudioCraft AI audio generation: - Gradio UI with tabs for all 5 model families (MusicGen, AudioGen, MAGNeT, MusicGen Style, JASCO) - REST API with FastAPI, OpenAPI docs, and API key auth - VRAM management with ComfyUI coexistence support - SQLite database for project/generation history - Batch processing queue for async generation - Docker deployment optimized for RunPod with RTX 4090 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
95 lines
3.4 KiB
Python
95 lines
3.4 KiB
Python
"""Application settings with environment variable support."""
|
|
|
|
from functools import lru_cache
|
|
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
from pydantic import Field
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Application configuration with environment variable support.
|
|
|
|
All settings can be overridden via environment variables prefixed with AUDIOCRAFT_.
|
|
Example: AUDIOCRAFT_API_PORT=8080
|
|
"""
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_prefix="AUDIOCRAFT_",
|
|
env_file=".env",
|
|
env_file_encoding="utf-8",
|
|
extra="ignore",
|
|
)
|
|
|
|
# Server Configuration
|
|
host: str = Field(default="0.0.0.0", description="Server bind host")
|
|
gradio_port: int = Field(default=7860, description="Gradio UI port")
|
|
api_port: int = Field(default=8000, description="FastAPI port")
|
|
|
|
# Paths
|
|
data_dir: Path = Field(default=Path("./data"), description="Data directory")
|
|
output_dir: Path = Field(default=Path("./outputs"), description="Generated audio output")
|
|
cache_dir: Path = Field(default=Path("./cache"), description="Model cache directory")
|
|
models_config: Path = Field(
|
|
default=Path("./config/models.yaml"), description="Model registry config"
|
|
)
|
|
|
|
# VRAM Management
|
|
comfyui_reserve_gb: float = Field(
|
|
default=10.0, description="VRAM reserved for ComfyUI (GB)"
|
|
)
|
|
safety_buffer_gb: float = Field(
|
|
default=1.0, description="Safety buffer to prevent OOM (GB)"
|
|
)
|
|
idle_unload_minutes: int = Field(
|
|
default=15, description="Unload models after idle time (minutes)"
|
|
)
|
|
max_cached_models: int = Field(
|
|
default=2, description="Maximum number of models to keep loaded"
|
|
)
|
|
|
|
# API Authentication
|
|
api_key: Optional[str] = Field(default=None, description="API key for authentication")
|
|
cors_origins: list[str] = Field(
|
|
default=["*"], description="Allowed CORS origins"
|
|
)
|
|
|
|
# Generation Defaults
|
|
default_duration: float = Field(default=10.0, description="Default generation duration")
|
|
max_duration: float = Field(default=300.0, description="Maximum generation duration")
|
|
default_batch_size: int = Field(default=1, description="Default batch size")
|
|
max_batch_size: int = Field(default=8, description="Maximum batch size")
|
|
max_queue_size: int = Field(default=100, description="Maximum generation queue size")
|
|
|
|
# Database
|
|
database_url: str = Field(
|
|
default="sqlite+aiosqlite:///./data/audiocraft.db",
|
|
description="Database connection URL",
|
|
)
|
|
|
|
# Logging
|
|
log_level: str = Field(default="INFO", description="Logging level")
|
|
|
|
def ensure_directories(self) -> None:
|
|
"""Create required directories if they don't exist."""
|
|
self.data_dir.mkdir(parents=True, exist_ok=True)
|
|
self.output_dir.mkdir(parents=True, exist_ok=True)
|
|
self.cache_dir.mkdir(parents=True, exist_ok=True)
|
|
(self.data_dir / "presets").mkdir(parents=True, exist_ok=True)
|
|
|
|
@property
|
|
def database_path(self) -> Path:
|
|
"""Extract database file path from URL."""
|
|
if self.database_url.startswith("sqlite"):
|
|
# Handle both sqlite:/// and sqlite+aiosqlite:///
|
|
path = self.database_url.split("///")[-1]
|
|
return Path(path)
|
|
raise ValueError("Only SQLite databases are supported")
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
"""Get cached settings instance."""
|
|
return Settings()
|