Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -94,7 +94,7 @@ def get_speakers_dict():
|
|
94 |
|
95 |
@spaces.GPU()
|
96 |
def initialize_model_once():
|
97 |
-
"""Initialize model
|
98 |
global _tts_model, _speakers_dict, _model_initialized, _initialization_in_progress
|
99 |
|
100 |
if _model_initialized:
|
@@ -110,44 +110,34 @@ def initialize_model_once():
|
|
110 |
|
111 |
_initialization_in_progress = True
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
speakers
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
error_msg = str(e)
|
140 |
-
if "unsloth_compiled_module" in error_msg and attempt < max_retries:
|
141 |
-
logger.warning(f"Unsloth compilation failed (attempt {attempt + 1}/{max_retries + 1}), retrying...")
|
142 |
-
time.sleep(2) # Brief delay before retry
|
143 |
-
continue
|
144 |
-
else:
|
145 |
-
logger.error(f"Failed to initialize model: {e}")
|
146 |
-
_initialization_in_progress = False
|
147 |
-
raise e
|
148 |
finally:
|
149 |
-
|
150 |
-
_initialization_in_progress = False
|
151 |
|
152 |
def validate_inputs(text, temperature, top_k, top_p, max_tokens):
|
153 |
"""Same validation as your old version"""
|
|
|
94 |
|
95 |
@spaces.GPU()
|
96 |
def initialize_model_once():
|
97 |
+
"""Initialize model exactly like your old working version"""
|
98 |
global _tts_model, _speakers_dict, _model_initialized, _initialization_in_progress
|
99 |
|
100 |
if _model_initialized:
|
|
|
110 |
|
111 |
_initialization_in_progress = True
|
112 |
|
113 |
+
try:
|
114 |
+
logger.info("Initializing Bambara TTS model...")
|
115 |
+
start_time = time.time()
|
116 |
+
|
117 |
+
# Use the correct import path
|
118 |
+
from maliba_ai.tts.inference import BambaraTTSInference
|
119 |
+
|
120 |
+
model = BambaraTTSInference()
|
121 |
+
speakers = get_speakers_dict()
|
122 |
+
|
123 |
+
if not speakers:
|
124 |
+
raise ValueError("Failed to load speakers dictionary")
|
125 |
+
|
126 |
+
_tts_model = model
|
127 |
+
_speakers_dict = speakers
|
128 |
+
_model_initialized = True
|
129 |
+
|
130 |
+
elapsed = time.time() - start_time
|
131 |
+
logger.info(f"Model initialized successfully in {elapsed:.2f} seconds!")
|
132 |
+
|
133 |
+
return _tts_model, _speakers_dict
|
134 |
+
|
135 |
+
except Exception as e:
|
136 |
+
logger.error(f"Failed to initialize model: {e}")
|
137 |
+
_initialization_in_progress = False
|
138 |
+
raise e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
finally:
|
140 |
+
_initialization_in_progress = False
|
|
|
141 |
|
142 |
def validate_inputs(text, temperature, top_k, top_p, max_tokens):
|
143 |
"""Same validation as your old version"""
|