Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -25,21 +25,6 @@ if is_restricted_environment():
|
|
25 |
else:
|
26 |
print("π§ Local environment detected - Unsloth optimizations enabled")
|
27 |
|
28 |
-
# Check if we're in ZeroGPU or similar restricted environment
|
29 |
-
def is_restricted_environment():
|
30 |
-
return (
|
31 |
-
os.getenv("ZERO_GPU") or
|
32 |
-
"zero" in str(os.getenv("SPACE_ID", "")).lower() or
|
33 |
-
os.getenv("SPACES_ZERO_GPU")
|
34 |
-
)
|
35 |
-
|
36 |
-
# Disable Unsloth optimizations in restricted environments
|
37 |
-
if is_restricted_environment():
|
38 |
-
os.environ["UNSLOTH_DISABLE"] = "1"
|
39 |
-
os.environ["DISABLE_UNSLOTH"] = "1"
|
40 |
-
os.environ["UNSLOTH_IGNORE_ERRORS"] = "1"
|
41 |
-
print("π ZeroGPU detected - Unsloth optimizations disabled for compatibility")
|
42 |
-
|
43 |
import torch
|
44 |
import gradio as gr
|
45 |
import numpy as np
|
@@ -94,7 +79,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,31 +95,40 @@ def initialize_model_once():
|
|
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 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
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
|
@@ -406,7 +400,7 @@ def build_interface():
|
|
406 |
- **π± Usage**: Educational, accessibility, and cultural preservation
|
407 |
|
408 |
### π Available Speakers:
|
409 |
-
{
|
410 |
|
411 |
**License**: Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0)
|
412 |
|
|
|
25 |
else:
|
26 |
print("π§ Local environment detected - Unsloth optimizations enabled")
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
import torch
|
29 |
import gradio as gr
|
30 |
import numpy as np
|
|
|
79 |
|
80 |
@spaces.GPU()
|
81 |
def initialize_model_once():
|
82 |
+
"""Initialize model with retry logic for Unsloth failures"""
|
83 |
global _tts_model, _speakers_dict, _model_initialized, _initialization_in_progress
|
84 |
|
85 |
if _model_initialized:
|
|
|
95 |
|
96 |
_initialization_in_progress = True
|
97 |
|
98 |
+
max_retries = 2
|
99 |
+
retry_delay = 5 # seconds
|
100 |
+
|
101 |
try:
|
102 |
logger.info("Initializing Bambara TTS model...")
|
103 |
start_time = time.time()
|
104 |
|
|
|
105 |
from maliba_ai.tts.inference import BambaraTTSInference
|
106 |
|
107 |
+
for attempt in range(max_retries):
|
108 |
+
try:
|
109 |
+
model = BambaraTTSInference()
|
110 |
+
speakers = get_speakers_dict()
|
111 |
+
|
112 |
+
if not speakers:
|
113 |
+
raise ValueError("Failed to load speakers dictionary")
|
114 |
+
|
115 |
+
_tts_model = model
|
116 |
+
_speakers_dict = speakers
|
117 |
+
_model_initialized = True
|
118 |
+
|
119 |
+
elapsed = time.time() - start_time
|
120 |
+
logger.info(f"Model initialized successfully in {elapsed:.2f} seconds!")
|
121 |
+
return _tts_model, _speakers_dict
|
122 |
+
|
123 |
+
except Exception as e:
|
124 |
+
if "unsloth_compiled_module_qwen2" in str(e) and attempt < max_retries - 1:
|
125 |
+
logger.warning(f"Unsloth compilation failed, retrying in {retry_delay} seconds... (attempt {attempt + 1}/{max_retries})")
|
126 |
+
time.sleep(retry_delay)
|
127 |
+
else:
|
128 |
+
raise e
|
129 |
+
|
130 |
except Exception as e:
|
131 |
+
logger.error(f"Failed to initialize model after {max_retries} attempts: {e}")
|
|
|
132 |
raise e
|
133 |
finally:
|
134 |
_initialization_in_progress = False
|
|
|
400 |
- **π± Usage**: Educational, accessibility, and cultural preservation
|
401 |
|
402 |
### π Available Speakers:
|
403 |
+
{ettes.join(SPEAKER_NAMES)}
|
404 |
|
405 |
**License**: Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0)
|
406 |
|