Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -104,7 +104,7 @@ def initialize_model_once():
|
|
104 |
start_time = time.time()
|
105 |
|
106 |
# Use the new import structure from the README
|
107 |
-
from maliba_ai.tts import BambaraTTSInference
|
108 |
|
109 |
model = BambaraTTSInference()
|
110 |
speakers = get_speakers_dict()
|
@@ -233,7 +233,7 @@ def get_speaker_names():
|
|
233 |
|
234 |
SPEAKER_NAMES = get_speaker_names()
|
235 |
|
236 |
-
# Examples
|
237 |
examples = [
|
238 |
["Aw ni ce", "Adama"], # Natural conversational greeting
|
239 |
["Mali bɛna diya kɔsɛbɛ, ka a da a kan baara bɛ ka kɛ.", "Moussa"], # Clear pronunciation for informative content
|
@@ -244,32 +244,37 @@ examples = [
|
|
244 |
["Aw ni ce. Ne tɔgɔ ye Adama. Awɔ, ne ye maliden de ye. Aw Sanbɛ Sanbɛ. San min tɛ ɲinan ye, an bɛɛ ka jɛ ka o seli ɲɔgɔn fɛ, hɛɛrɛ ni lafiya la. Ala ka Mali suma. Ala ka Mali yiriwa. Ala ka Mali taa ɲɛ. Ala ka an ka seliw caya. Ala ka yafa an bɛɛ ma.", "Moussa"], # Clear pronunciation for heartfelt long message
|
245 |
["An dɔlakelen bɛ masike bilenman don ka tɔw gɛn.", "Bourama"], # Most stable for complex statement
|
246 |
["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"], # Expressive delivery for personal greeting
|
|
|
|
|
|
|
|
|
|
|
247 |
]
|
248 |
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
base_examples = examples.copy()
|
253 |
|
254 |
-
#
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
#
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
if
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
|
|
271 |
|
272 |
-
return
|
273 |
|
274 |
def build_interface():
|
275 |
"""Build the Gradio interface - simplified like your old working version"""
|
@@ -369,17 +374,15 @@ def build_interface():
|
|
369 |
|
370 |
gr.Markdown("**Click any example below:**")
|
371 |
|
372 |
-
# Use
|
373 |
-
|
374 |
|
375 |
-
for i, (text, speaker) in enumerate(
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
outputs=[text_input, speaker_dropdown, use_advanced, temperature, top_k, top_p, max_tokens]
|
382 |
-
)
|
383 |
|
384 |
with gr.Accordion("About", open=False):
|
385 |
gr.Markdown(f"""
|
@@ -441,8 +444,7 @@ def build_interface():
|
|
441 |
def main():
|
442 |
"""Main function to launch the Gradio interface"""
|
443 |
logger.info("Starting Bambara TTS Gradio interface.")
|
444 |
-
|
445 |
-
# DO NOT preload - let it initialize on first request only (like your working version)
|
446 |
interface = build_interface()
|
447 |
interface.launch(
|
448 |
server_name="0.0.0.0",
|
|
|
104 |
start_time = time.time()
|
105 |
|
106 |
# Use the new import structure from the README
|
107 |
+
from maliba_ai.tts.inference import BambaraTTSInference
|
108 |
|
109 |
model = BambaraTTSInference()
|
110 |
speakers = get_speakers_dict()
|
|
|
233 |
|
234 |
SPEAKER_NAMES = get_speaker_names()
|
235 |
|
236 |
+
# Examples representing ALL 10 speakers - with fallbacks for missing speakers
|
237 |
examples = [
|
238 |
["Aw ni ce", "Adama"], # Natural conversational greeting
|
239 |
["Mali bɛna diya kɔsɛbɛ, ka a da a kan baara bɛ ka kɛ.", "Moussa"], # Clear pronunciation for informative content
|
|
|
244 |
["Aw ni ce. Ne tɔgɔ ye Adama. Awɔ, ne ye maliden de ye. Aw Sanbɛ Sanbɛ. San min tɛ ɲinan ye, an bɛɛ ka jɛ ka o seli ɲɔgɔn fɛ, hɛɛrɛ ni lafiya la. Ala ka Mali suma. Ala ka Mali yiriwa. Ala ka Mali taa ɲɛ. Ala ka an ka seliw caya. Ala ka yafa an bɛɛ ma.", "Moussa"], # Clear pronunciation for heartfelt long message
|
245 |
["An dɔlakelen bɛ masike bilenman don ka tɔw gɛn.", "Bourama"], # Most stable for complex statement
|
246 |
["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"], # Expressive delivery for personal greeting
|
247 |
+
["To tɔ nantan ni lafiya, o ka fisa ni so fa dumuniba kɛlɛma ye.", "Amadou"], # Warm and friendly voice for wisdom saying
|
248 |
+
["Mali ye jamana ɲuman ye!", "Bakary"], # Deep, authoritative tone for patriotic statement
|
249 |
+
["An ka ɲɔgɔn dɛmɛ ka baara kɛ ɲɔgɔn fɛ", "Ngolo"], # Youthful and energetic for collaboration
|
250 |
+
["Hakili bɛ yɔrɔ min na, sabali bɛ yen", "Ibrahima"], # Calm and measured for philosophical thought
|
251 |
+
["Aw ni ce. Seidu bɛ aw fo wa aw ka yafa a ma, ka da a kan tuma dɔw la kow ka can.", "Amara"], # Melodic and smooth for poetic expression
|
252 |
]
|
253 |
|
254 |
+
def get_safe_examples():
|
255 |
+
"""Get examples with speaker fallbacks for missing speakers"""
|
256 |
+
safe_examples = []
|
|
|
257 |
|
258 |
+
# Fallback mapping for missing speakers
|
259 |
+
fallback_speakers = {
|
260 |
+
"Amadou": "Adama", # Warm -> Natural conversational
|
261 |
+
"Bakary": "Modibo", # Authoritative -> Expressive
|
262 |
+
"Ngolo": "Adama", # Youthful -> Natural conversational
|
263 |
+
"Ibrahima": "Seydou", # Calm -> Balanced
|
264 |
+
"Amara": "Moussa" # Melodic -> Clear pronunciation
|
265 |
+
}
|
266 |
+
|
267 |
+
for text, speaker in examples:
|
268 |
+
# Use original speaker if available, otherwise use fallback
|
269 |
+
if speaker in SPEAKER_NAMES:
|
270 |
+
safe_examples.append([text, speaker])
|
271 |
+
elif speaker in fallback_speakers and fallback_speakers[speaker] in SPEAKER_NAMES:
|
272 |
+
safe_examples.append([text, fallback_speakers[speaker]])
|
273 |
+
else:
|
274 |
+
# Final fallback to first available speaker
|
275 |
+
safe_examples.append([text, SPEAKER_NAMES[0]])
|
276 |
|
277 |
+
return safe_examples
|
278 |
|
279 |
def build_interface():
|
280 |
"""Build the Gradio interface - simplified like your old working version"""
|
|
|
374 |
|
375 |
gr.Markdown("**Click any example below:**")
|
376 |
|
377 |
+
# Use safe examples with fallbacks for missing speakers
|
378 |
+
safe_examples = get_safe_examples()
|
379 |
|
380 |
+
for i, (text, speaker) in enumerate(safe_examples):
|
381 |
+
btn = gr.Button(f"{text[:30]}{'...' if len(text) > 30 else ''}", size="sm")
|
382 |
+
btn.click(
|
383 |
+
fn=lambda t=text, s=speaker: load_example(t, s),
|
384 |
+
outputs=[text_input, speaker_dropdown, use_advanced, temperature, top_k, top_p, max_tokens]
|
385 |
+
)
|
|
|
|
|
386 |
|
387 |
with gr.Accordion("About", open=False):
|
388 |
gr.Markdown(f"""
|
|
|
444 |
def main():
|
445 |
"""Main function to launch the Gradio interface"""
|
446 |
logger.info("Starting Bambara TTS Gradio interface.")
|
447 |
+
|
|
|
448 |
interface = build_interface()
|
449 |
interface.launch(
|
450 |
server_name="0.0.0.0",
|