File size: 3,750 Bytes
7fa9d90 cce7cd9 7fa9d90 347b758 7fa9d90 1a02e5e 7fa9d90 | 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | """
Base Configuration for NCAkit
Provides centralized configuration management for all modules.
"""
import os
from pathlib import Path
from pydantic_settings import BaseSettings
from typing import Optional, Dict, Any
class BaseConfig(BaseSettings):
"""
Base configuration class that all module configs should extend.
Provides common settings and utilities.
"""
# Server Configuration
port: int = 8880
log_level: str = "info"
debug: bool = False
# Environment
docker: bool = False
dev: bool = False
data_dir_path: Optional[str] = None
class Config:
env_file = ".env"
case_sensitive = False
extra = "ignore"
@property
def base_data_dir(self) -> Path:
"""Get the base data directory path"""
if self.data_dir_path:
return Path(self.data_dir_path)
if self.docker:
return Path("/data")
# For local development
home = Path.home()
return home / ".ncakit"
def ensure_base_directories(self):
"""Ensure base directories exist"""
self.base_data_dir.mkdir(parents=True, exist_ok=True)
class NCAkitConfig(BaseConfig):
"""
Main NCAkit configuration.
Aggregates all module-specific settings.
"""
# ===================
# Video Creator Module Config
# ===================
pexels_api_key: Optional[str] = None
pixabay_api_key: Optional[str] = None # Optional: Pixabay API for additional video source
hf_tts: Optional[str] = None
whisper_model: str = "tiny.en"
whisper_verbose: bool = False
concurrency: int = 1
video_cache_size_in_bytes: int = 2684354560 # 2.5GB
# ===================
# Add new module configs here
# Example:
# openai_api_key: Optional[str] = None
# ===================
# ===================
# Story Reels Module Config
# ===================
nvidia_api_key: Optional[str] = None # NVIDIA API key (primary)
cf_url: Optional[str] = None # Cloudflare Worker URL (fallback)
cf_api: Optional[str] = None # Cloudflare API key (fallback)
gemini_api_key: Optional[str] = None # For AI script generation (fallback)
groq_api: Optional[str] = None # Groq API key (primary for script generation)
# ===================
# HF Cloud Storage (Optional)
# ===================
hf_repo: Optional[str] = None # HF repo for videos (e.g., "username/ncakit-videos")
# Note: Uses HF_TOKEN from environment for auth
@property
def videos_dir_path(self) -> Path:
"""Directory for storing generated videos"""
path = self.base_data_dir / "videos"
path.mkdir(parents=True, exist_ok=True)
return path
@property
def temp_dir_path(self) -> Path:
"""Directory for temporary files"""
path = self.base_data_dir / "temp"
path.mkdir(parents=True, exist_ok=True)
return path
@property
def whisper_model_dir(self) -> Path:
"""Directory for Whisper models"""
path = self.base_data_dir / "whisper_models"
path.mkdir(parents=True, exist_ok=True)
return path
@property
def music_dir_path(self) -> Path:
"""Directory for music files"""
return Path(__file__).parent / "static" / "music"
def ensure_directories(self):
"""Ensure all required directories exist"""
self.ensure_base_directories()
self.videos_dir_path.mkdir(parents=True, exist_ok=True)
self.temp_dir_path.mkdir(parents=True, exist_ok=True)
self.whisper_model_dir.mkdir(parents=True, exist_ok=True)
# Global config instance
config = NCAkitConfig()
|