Spaces:
Running
Running
| import os | |
| from typing import Dict, Any | |
| class Config: | |
| """Application configuration class""" | |
| # Novita AI Configuration | |
| NOVITA_API_KEY = os.getenv('NOVITA_API_KEY', '') | |
| NOVITA_API_BASE_URL = os.getenv('NOVITA_API_BASE_URL', 'https://api.novita.ai/v3') | |
| # Application Configuration | |
| APP_TITLE = os.getenv('APP_TITLE', 'Novita AI Seedance V1 Video Generator') | |
| APP_ICON = os.getenv('APP_ICON', '🎬') | |
| MAX_FILE_SIZE_MB = int(os.getenv('MAX_FILE_SIZE_MB', '10')) | |
| DEFAULT_RESOLUTION = os.getenv('DEFAULT_RESOLUTION', '720p') | |
| DEFAULT_DURATION = int(os.getenv('DEFAULT_DURATION', '5')) | |
| DEFAULT_ASPECT_RATIO = os.getenv('DEFAULT_ASPECT_RATIO', '16:9') | |
| # Timeout Configuration (increased for reliability) | |
| BASE_TIMEOUT_SECONDS = int(os.getenv('BASE_TIMEOUT_SECONDS', '900')) # 15 minutes base | |
| PRO_MODEL_EXTRA_TIMEOUT = int(os.getenv('PRO_MODEL_EXTRA_TIMEOUT', '600')) # 10 min extra for Pro | |
| RESOLUTION_720P_MULTIPLIER = float(os.getenv('RESOLUTION_720P_MULTIPLIER', '1.2')) | |
| RESOLUTION_1080P_MULTIPLIER = float(os.getenv('RESOLUTION_1080P_MULTIPLIER', '1.5')) | |
| LONG_VIDEO_EXTRA_TIMEOUT = int(os.getenv('LONG_VIDEO_EXTRA_TIMEOUT', '300')) # 5 min extra for 10s videos | |
| # API Configuration | |
| STATUS_CHECK_INTERVAL = int(os.getenv('STATUS_CHECK_INTERVAL', '5')) # Check every 5 seconds | |
| MAX_RETRIES = int(os.getenv('MAX_RETRIES', '3')) | |
| REQUEST_TIMEOUT = int(os.getenv('REQUEST_TIMEOUT', '30')) | |
| # Model Configuration | |
| MODEL_OPTIONS = { | |
| "Seedance V1 Lite (Text-to-Video)": "seedance-v1-lite-t2v", | |
| "Seedance V1 Pro (Text-to-Video)": "seedance-v1-pro-t2v", | |
| "Seedance V1 Lite (Image-to-Video)": "seedance-v1-lite-i2v", | |
| "Seedance V1 Pro (Image-to-Video)": "seedance-v1-pro-i2v" | |
| } | |
| # Supported Parameters | |
| RESOLUTIONS = ["480p", "720p", "1080p"] | |
| DURATIONS = [5, 10] | |
| ASPECT_RATIOS = ["21:9", "16:9", "4:3", "1:1", "3:4", "9:16", "9:21"] | |
| SUPPORTED_IMAGE_FORMATS = ['png', 'jpg', 'jpeg'] | |
| def get_resolution_multiplier(cls, resolution: str) -> float: | |
| """Get resolution multiplier""" | |
| multipliers = { | |
| "480p": 1.0, | |
| "720p": cls.RESOLUTION_720P_MULTIPLIER, | |
| "1080p": cls.RESOLUTION_1080P_MULTIPLIER | |
| } | |
| return multipliers.get(resolution, 1.0) | |
| def calculate_timeout(cls, model_type: str, resolution: str, duration: int) -> int: | |
| """Calculate dynamic timeout""" | |
| base_time = cls.BASE_TIMEOUT_SECONDS | |
| # Extra time for Pro models | |
| if "pro" in model_type.lower(): | |
| base_time += cls.PRO_MODEL_EXTRA_TIMEOUT | |
| # Resolution multiplier | |
| base_time *= cls.get_resolution_multiplier(resolution) | |
| # Extra time for long videos | |
| if duration >= 10: | |
| base_time += cls.LONG_VIDEO_EXTRA_TIMEOUT | |
| return int(base_time) | |
| def validate_config(cls) -> Dict[str, Any]: | |
| """Validate configuration""" | |
| errors = [] | |
| warnings = [] | |
| if not cls.NOVITA_API_KEY: | |
| warnings.append("Default API key not set") | |
| if cls.MAX_FILE_SIZE_MB > 100: | |
| warnings.append(f"File size limit is large: {cls.MAX_FILE_SIZE_MB}MB") | |
| if cls.BASE_TIMEOUT_SECONDS < 60: | |
| errors.append("Base timeout too short") | |
| return { | |
| "valid": len(errors) == 0, | |
| "errors": errors, | |
| "warnings": warnings | |
| } | |
| # Load environment variables (if .env file exists) | |
| try: | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| except ImportError: | |
| pass # dotenv is not a required dependency |