Darveht commited on
Commit
c9d4539
·
verified ·
1 Parent(s): bc1fa7d

Upload config.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. config.py +260 -0
config.py ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ZenVision AI Subtitle Generator - Configuration
3
+ Configuración avanzada del modelo de 3GB+
4
+ """
5
+
6
+ import os
7
+ from dataclasses import dataclass
8
+ from typing import Dict, List, Optional
9
+
10
+ @dataclass
11
+ class ModelConfig:
12
+ """Configuración de modelos de IA"""
13
+
14
+ # Whisper Configuration
15
+ whisper_model_size: str = "large-v2" # tiny, base, small, medium, large, large-v2
16
+ whisper_device: str = "auto" # auto, cuda, cpu, mps
17
+
18
+ # Translation Models
19
+ translation_model: str = "Helsinki-NLP/opus-mt-en-mul"
20
+ use_google_translate: bool = True
21
+
22
+ # Sentiment Analysis
23
+ sentiment_model: str = "cardiffnlp/twitter-roberta-base-sentiment-latest"
24
+
25
+ # Emotion Detection
26
+ emotion_model: str = "j-hartmann/emotion-english-distilroberta-base"
27
+
28
+ # BERT Configuration
29
+ bert_model: str = "bert-base-multilingual-cased"
30
+
31
+ # spaCy Models
32
+ spacy_models: Dict[str, str] = None
33
+
34
+ def __post_init__(self):
35
+ if self.spacy_models is None:
36
+ self.spacy_models = {
37
+ "en": "en_core_web_sm",
38
+ "es": "es_core_news_sm",
39
+ "fr": "fr_core_news_sm",
40
+ "de": "de_core_news_sm",
41
+ "it": "it_core_news_sm",
42
+ "pt": "pt_core_news_sm"
43
+ }
44
+
45
+ @dataclass
46
+ class ProcessingConfig:
47
+ """Configuración de procesamiento"""
48
+
49
+ # Audio Processing
50
+ sample_rate: int = 16000
51
+ audio_format: str = "wav"
52
+
53
+ # Video Processing
54
+ video_codec: str = "libx264"
55
+ audio_codec: str = "aac"
56
+
57
+ # Subtitle Configuration
58
+ max_chars_per_line: int = 42
59
+ max_lines_per_subtitle: int = 2
60
+ min_subtitle_duration: float = 1.0
61
+ max_subtitle_duration: float = 7.0
62
+
63
+ # Language Support
64
+ supported_languages: List[str] = None
65
+
66
+ def __post_init__(self):
67
+ if self.supported_languages is None:
68
+ self.supported_languages = [
69
+ "es", "en", "fr", "de", "it", "pt",
70
+ "zh", "ja", "ko", "ru", "ar", "hi"
71
+ ]
72
+
73
+ @dataclass
74
+ class UIConfig:
75
+ """Configuración de interfaz de usuario"""
76
+
77
+ # Gradio Configuration
78
+ server_name: str = "0.0.0.0"
79
+ server_port: int = 7860
80
+ share: bool = False
81
+
82
+ # Theme and Styling
83
+ theme: str = "soft"
84
+ title: str = "ZenVision AI Subtitle Generator"
85
+
86
+ # File Upload Limits
87
+ max_file_size: int = 500 * 1024 * 1024 # 500MB
88
+ allowed_video_formats: List[str] = None
89
+
90
+ def __post_init__(self):
91
+ if self.allowed_video_formats is None:
92
+ self.allowed_video_formats = [
93
+ ".mp4", ".avi", ".mov", ".mkv", ".webm",
94
+ ".flv", ".wmv", ".m4v", ".3gp"
95
+ ]
96
+
97
+ @dataclass
98
+ class SystemConfig:
99
+ """Configuración del sistema"""
100
+
101
+ # Cache and Storage
102
+ cache_dir: str = os.path.expanduser("~/.zenvision/cache")
103
+ models_dir: str = os.path.expanduser("~/.zenvision/models")
104
+ temp_dir: str = "/tmp/zenvision"
105
+
106
+ # Performance
107
+ max_workers: int = 4
108
+ batch_size: int = 16
109
+
110
+ # Memory Management
111
+ max_memory_usage: float = 0.8 # 80% of available RAM
112
+ clear_cache_on_exit: bool = True
113
+
114
+ # Logging
115
+ log_level: str = "INFO"
116
+ log_file: Optional[str] = None
117
+
118
+ class ZenVisionConfig:
119
+ """Configuración principal de ZenVision"""
120
+
121
+ def __init__(self):
122
+ self.model = ModelConfig()
123
+ self.processing = ProcessingConfig()
124
+ self.ui = UIConfig()
125
+ self.system = SystemConfig()
126
+
127
+ # Load from environment variables
128
+ self._load_from_env()
129
+
130
+ # Create directories
131
+ self._create_directories()
132
+
133
+ def _load_from_env(self):
134
+ """Carga configuración desde variables de entorno"""
135
+
136
+ # Model configuration
137
+ if os.getenv("ZENVISION_WHISPER_MODEL"):
138
+ self.model.whisper_model_size = os.getenv("ZENVISION_WHISPER_MODEL")
139
+
140
+ if os.getenv("ZENVISION_DEVICE"):
141
+ self.model.whisper_device = os.getenv("ZENVISION_DEVICE")
142
+
143
+ # UI configuration
144
+ if os.getenv("ZENVISION_PORT"):
145
+ self.ui.server_port = int(os.getenv("ZENVISION_PORT"))
146
+
147
+ if os.getenv("ZENVISION_SHARE"):
148
+ self.ui.share = os.getenv("ZENVISION_SHARE").lower() == "true"
149
+
150
+ # System configuration
151
+ if os.getenv("ZENVISION_CACHE_DIR"):
152
+ self.system.cache_dir = os.getenv("ZENVISION_CACHE_DIR")
153
+
154
+ if os.getenv("ZENVISION_MAX_WORKERS"):
155
+ self.system.max_workers = int(os.getenv("ZENVISION_MAX_WORKERS"))
156
+
157
+ def _create_directories(self):
158
+ """Crea directorios necesarios"""
159
+ directories = [
160
+ self.system.cache_dir,
161
+ self.system.models_dir,
162
+ self.system.temp_dir
163
+ ]
164
+
165
+ for directory in directories:
166
+ os.makedirs(directory, exist_ok=True)
167
+
168
+ def get_model_path(self, model_name: str) -> str:
169
+ """Obtiene la ruta de un modelo"""
170
+ return os.path.join(self.system.models_dir, model_name)
171
+
172
+ def get_cache_path(self, cache_name: str) -> str:
173
+ """Obtiene la ruta de cache"""
174
+ return os.path.join(self.system.cache_dir, cache_name)
175
+
176
+ def to_dict(self) -> Dict:
177
+ """Convierte configuración a diccionario"""
178
+ return {
179
+ "model": self.model.__dict__,
180
+ "processing": self.processing.__dict__,
181
+ "ui": self.ui.__dict__,
182
+ "system": self.system.__dict__
183
+ }
184
+
185
+ # Configuración global
186
+ config = ZenVisionConfig()
187
+
188
+ # Emotion color mapping
189
+ EMOTION_COLORS = {
190
+ "joy": "#FFD700", # Gold
191
+ "sadness": "#4169E1", # Royal Blue
192
+ "anger": "#DC143C", # Crimson
193
+ "fear": "#8A2BE2", # Blue Violet
194
+ "surprise": "#FF8C00", # Dark Orange
195
+ "disgust": "#32CD32", # Lime Green
196
+ "neutral": "#FFFFFF", # White
197
+ "love": "#FF69B4", # Hot Pink
198
+ "optimism": "#00FF7F", # Spring Green
199
+ "pessimism": "#696969" # Dim Gray
200
+ }
201
+
202
+ # Language mappings
203
+ LANGUAGE_NAMES = {
204
+ "es": "Español",
205
+ "en": "English",
206
+ "fr": "Français",
207
+ "de": "Deutsch",
208
+ "it": "Italiano",
209
+ "pt": "Português",
210
+ "zh": "中文",
211
+ "ja": "日本語",
212
+ "ko": "한국어",
213
+ "ru": "Русский",
214
+ "ar": "العربية",
215
+ "hi": "हिन्दी"
216
+ }
217
+
218
+ # Model size information
219
+ MODEL_SIZES = {
220
+ "whisper": {
221
+ "tiny": "39 MB",
222
+ "base": "74 MB",
223
+ "small": "244 MB",
224
+ "medium": "769 MB",
225
+ "large": "1550 MB",
226
+ "large-v2": "1550 MB"
227
+ },
228
+ "bert-multilingual": "400 MB",
229
+ "roberta-sentiment": "200 MB",
230
+ "distilroberta-emotion": "300 MB",
231
+ "translation-models": "500 MB"
232
+ }
233
+
234
+ # Performance benchmarks
235
+ PERFORMANCE_BENCHMARKS = {
236
+ "accuracy": {
237
+ "transcription": {
238
+ "en": 0.972,
239
+ "es": 0.958,
240
+ "fr": 0.945,
241
+ "de": 0.931,
242
+ "it": 0.948,
243
+ "pt": 0.952
244
+ },
245
+ "translation": {
246
+ "en-es": 0.89,
247
+ "en-fr": 0.87,
248
+ "en-de": 0.84,
249
+ "es-en": 0.91,
250
+ "fr-en": 0.88
251
+ },
252
+ "emotion_detection": 0.85,
253
+ "sentiment_analysis": 0.94
254
+ },
255
+ "speed": {
256
+ "cpu_i7": 0.3, # x real time
257
+ "gpu_rtx3080": 2.1, # x real time
258
+ "gpu_rtx4090": 3.8 # x real time
259
+ }
260
+ }