Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ import numpy as np
|
|
11 |
import spaces
|
12 |
import logging
|
13 |
from huggingface_hub import login
|
14 |
-
|
15 |
|
16 |
torch._dynamo.config.disable = True
|
17 |
torch._dynamo.config.suppress_errors = True
|
@@ -28,36 +28,39 @@ if hf_token:
|
|
28 |
tts_model = None
|
29 |
speakers_dict = None
|
30 |
model_initialized = False
|
|
|
31 |
|
32 |
@spaces.GPU()
|
33 |
def initialize_model():
|
34 |
"""Initialize the TTS model and speakers - called once with GPU context"""
|
35 |
-
global tts_model, speakers_dict, model_initialized
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
from maliba_ai.tts.inference import BambaraTTSInference
|
42 |
-
from maliba_ai.config.speakers import Adame, Moussa, Bourama, Modibo, Seydou
|
43 |
-
|
44 |
-
|
45 |
-
tts_model = BambaraTTSInference()
|
46 |
-
|
47 |
-
speakers_dict = {
|
48 |
-
"Adame": Adame,
|
49 |
-
"Moussa": Moussa,
|
50 |
-
"Bourama": Bourama,
|
51 |
-
"Modibo": Modibo,
|
52 |
-
"Seydou": Seydou
|
53 |
-
}
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
return tts_model, speakers_dict
|
63 |
|
|
|
11 |
import spaces
|
12 |
import logging
|
13 |
from huggingface_hub import login
|
14 |
+
import threading
|
15 |
|
16 |
torch._dynamo.config.disable = True
|
17 |
torch._dynamo.config.suppress_errors = True
|
|
|
28 |
tts_model = None
|
29 |
speakers_dict = None
|
30 |
model_initialized = False
|
31 |
+
model_initialized_lock = threading.Lock()
|
32 |
|
33 |
@spaces.GPU()
|
34 |
def initialize_model():
|
35 |
"""Initialize the TTS model and speakers - called once with GPU context"""
|
36 |
+
global tts_model, speakers_dict, model_initialized, model_initialized_lock
|
37 |
|
38 |
+
# Always acquire lock first for async safety
|
39 |
+
with model_initialized_lock:
|
40 |
+
if not model_initialized:
|
41 |
+
logger.info("Initializing Bambara TTS model...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
try:
|
44 |
+
from maliba_ai.tts.inference import BambaraTTSInference
|
45 |
+
from maliba_ai.config.speakers import Adame, Moussa, Bourama, Modibo, Seydou
|
46 |
+
|
47 |
+
# All initialization inside the lock
|
48 |
+
tts_model = BambaraTTSInference()
|
49 |
+
speakers_dict = {
|
50 |
+
"Adame": Adame,
|
51 |
+
"Moussa": Moussa,
|
52 |
+
"Bourama": Bourama,
|
53 |
+
"Modibo": Modibo,
|
54 |
+
"Seydou": Seydou
|
55 |
+
}
|
56 |
+
|
57 |
+
# Set flag last, after everything is ready
|
58 |
+
model_initialized = True
|
59 |
+
logger.info("Model initialized successfully!")
|
60 |
+
|
61 |
+
except Exception as e:
|
62 |
+
logger.error(f"Failed to initialize model: {e}")
|
63 |
+
raise e
|
64 |
|
65 |
return tts_model, speakers_dict
|
66 |
|