Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
-
import os
|
4 |
import spaces
|
5 |
from huggingface_hub import login
|
|
|
|
|
6 |
from maliba_ai.tts.inference import BambaraTTSInference
|
7 |
from maliba_ai.config.speakers import Adame, Moussa, Bourama, Modibo, Seydou
|
8 |
|
9 |
-
|
10 |
hf_token = os.getenv("HF_TOKEN")
|
11 |
if hf_token:
|
12 |
login(token=hf_token)
|
13 |
|
14 |
-
|
15 |
print("Loading Bambara TTS model...")
|
16 |
tts = BambaraTTSInference()
|
17 |
print("Model loaded successfully!")
|
18 |
|
19 |
-
|
20 |
SPEAKERS = {
|
21 |
"Adame": Adame,
|
22 |
"Moussa": Moussa,
|
@@ -48,7 +59,13 @@ def generate_speech(text, speaker_name, use_advanced, temperature, top_k, top_p,
|
|
48 |
return None, "Please enter some Bambara text."
|
49 |
|
50 |
try:
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
speaker = SPEAKERS[speaker_name]
|
53 |
|
54 |
if use_advanced:
|
@@ -79,18 +96,13 @@ def generate_speech(text, speaker_name, use_advanced, temperature, top_k, top_p,
|
|
79 |
except Exception as e:
|
80 |
return None, f"❌ Error: {str(e)}"
|
81 |
|
82 |
-
|
83 |
examples = [
|
84 |
-
|
85 |
["Aw ni ce", "Adame"],
|
86 |
["I ni ce", "Moussa"],
|
87 |
["Aw ni tile", "Bourama"],
|
88 |
["I ka kene wa?", "Modibo"],
|
89 |
["Ala ka Mali suma", "Adame"],
|
90 |
-
|
91 |
["sigikafɔ kɔnɔ jamanaw ni ɲɔgɔn cɛ, olu ye a haminankow ye, wa o ko ninnu ka kan ka kɛ sariya ani tilennenya kɔnɔ", "Seydou"],
|
92 |
-
|
93 |
-
|
94 |
["Aw ni ce. Ne tɔgɔ ye Kaya Magan. Aw Sanbe Sanbe.", "Moussa"],
|
95 |
["An dɔlakelen bɛ masike bilenman don ka tɔw gɛn.", "Bourama"],
|
96 |
["Aw ni ce. Seidu bɛ aw fo wa aw ka yafa a ma, ka da a kan tuma dɔw la kow ka can.", "Modibo"],
|
@@ -104,6 +116,8 @@ with gr.Blocks(title="Bambara TTS - EXPERIMENTAL", theme=gr.themes.Soft()) as de
|
|
104 |
Convert Bambara text to speech using AI. This model is currently experimental.
|
105 |
|
106 |
**Bambara** is spoken by millions of people in Mali and West Africa.
|
|
|
|
|
107 |
""")
|
108 |
|
109 |
with gr.Row():
|
@@ -126,7 +140,6 @@ with gr.Blocks(title="Bambara TTS - EXPERIMENTAL", theme=gr.themes.Soft()) as de
|
|
126 |
generate_btn = gr.Button("🎵 Generate Speech", variant="primary", size="lg")
|
127 |
|
128 |
with gr.Column(scale=1):
|
129 |
-
|
130 |
use_advanced = gr.Checkbox(
|
131 |
label="⚙️ Use Advanced Settings",
|
132 |
value=False,
|
@@ -203,6 +216,8 @@ with gr.Blocks(title="Bambara TTS - EXPERIMENTAL", theme=gr.themes.Soft()) as de
|
|
203 |
gr.Markdown("""
|
204 |
**⚠️ This is an experimental Bambara TTS model.**
|
205 |
|
|
|
|
|
206 |
""")
|
207 |
|
208 |
def toggle_advanced(use_adv):
|
|
|
1 |
+
import os
|
2 |
+
import warnings
|
3 |
+
|
4 |
+
# Set environment variables BEFORE any imports to prevent CUDA initialization
|
5 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = "" # Hide CUDA during startup
|
6 |
+
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:128"
|
7 |
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
8 |
+
os.environ["CUDA_LAUNCH_BLOCKING"] = "1" # For debugging
|
9 |
+
|
10 |
+
# Suppress warnings
|
11 |
+
warnings.filterwarnings("ignore")
|
12 |
+
|
13 |
import gradio as gr
|
14 |
import numpy as np
|
|
|
15 |
import spaces
|
16 |
from huggingface_hub import login
|
17 |
+
|
18 |
+
# These imports should now work without CUDA errors
|
19 |
from maliba_ai.tts.inference import BambaraTTSInference
|
20 |
from maliba_ai.config.speakers import Adame, Moussa, Bourama, Modibo, Seydou
|
21 |
|
|
|
22 |
hf_token = os.getenv("HF_TOKEN")
|
23 |
if hf_token:
|
24 |
login(token=hf_token)
|
25 |
|
26 |
+
# Initialize TTS model (this will use CPU during startup)
|
27 |
print("Loading Bambara TTS model...")
|
28 |
tts = BambaraTTSInference()
|
29 |
print("Model loaded successfully!")
|
30 |
|
|
|
31 |
SPEAKERS = {
|
32 |
"Adame": Adame,
|
33 |
"Moussa": Moussa,
|
|
|
59 |
return None, "Please enter some Bambara text."
|
60 |
|
61 |
try:
|
62 |
+
# Re-enable CUDA for GPU context
|
63 |
+
import torch
|
64 |
+
if torch.cuda.is_available():
|
65 |
+
# Remove CUDA visibility restriction for GPU execution
|
66 |
+
if "CUDA_VISIBLE_DEVICES" in os.environ:
|
67 |
+
os.environ.pop("CUDA_VISIBLE_DEVICES", None)
|
68 |
+
|
69 |
speaker = SPEAKERS[speaker_name]
|
70 |
|
71 |
if use_advanced:
|
|
|
96 |
except Exception as e:
|
97 |
return None, f"❌ Error: {str(e)}"
|
98 |
|
|
|
99 |
examples = [
|
|
|
100 |
["Aw ni ce", "Adame"],
|
101 |
["I ni ce", "Moussa"],
|
102 |
["Aw ni tile", "Bourama"],
|
103 |
["I ka kene wa?", "Modibo"],
|
104 |
["Ala ka Mali suma", "Adame"],
|
|
|
105 |
["sigikafɔ kɔnɔ jamanaw ni ɲɔgɔn cɛ, olu ye a haminankow ye, wa o ko ninnu ka kan ka kɛ sariya ani tilennenya kɔnɔ", "Seydou"],
|
|
|
|
|
106 |
["Aw ni ce. Ne tɔgɔ ye Kaya Magan. Aw Sanbe Sanbe.", "Moussa"],
|
107 |
["An dɔlakelen bɛ masike bilenman don ka tɔw gɛn.", "Bourama"],
|
108 |
["Aw ni ce. Seidu bɛ aw fo wa aw ka yafa a ma, ka da a kan tuma dɔw la kow ka can.", "Modibo"],
|
|
|
116 |
Convert Bambara text to speech using AI. This model is currently experimental.
|
117 |
|
118 |
**Bambara** is spoken by millions of people in Mali and West Africa.
|
119 |
+
|
120 |
+
⚡ **Note**: Model loads on CPU during startup, then uses GPU for generation.
|
121 |
""")
|
122 |
|
123 |
with gr.Row():
|
|
|
140 |
generate_btn = gr.Button("🎵 Generate Speech", variant="primary", size="lg")
|
141 |
|
142 |
with gr.Column(scale=1):
|
|
|
143 |
use_advanced = gr.Checkbox(
|
144 |
label="⚙️ Use Advanced Settings",
|
145 |
value=False,
|
|
|
216 |
gr.Markdown("""
|
217 |
**⚠️ This is an experimental Bambara TTS model.**
|
218 |
|
219 |
+
The model loads on CPU during startup to avoid CUDA initialization errors,
|
220 |
+
then switches to GPU during speech generation for optimal performance.
|
221 |
""")
|
222 |
|
223 |
def toggle_advanced(use_adv):
|