sudoping01 commited on
Commit
9b1a61d
·
verified ·
1 Parent(s): e347941

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -36
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 with variety of lengths - use only available speakers with fallbacks
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
- # Additional examples for when all 10 speakers are available
250
- def get_examples_for_available_speakers():
251
- """Generate examples based on available speakers"""
252
- base_examples = examples.copy()
253
 
254
- # Add more examples if we have more speakers available
255
- if len(SPEAKER_NAMES) > 5:
256
- additional_examples = []
257
-
258
- # Add examples for additional speakers if they exist
259
- if "Amadou" in SPEAKER_NAMES:
260
- additional_examples.append(["To nantan ni lafiya, o ka fisa ni so fa dumuniba kɛlɛma ye.", "Amadou"])
261
- if "Bakary" in SPEAKER_NAMES:
262
- additional_examples.append(["Mali ye jamana ɲuman ye!", "Bakary"])
263
- if "Ngolo" in SPEAKER_NAMES:
264
- additional_examples.append(["An ka ɲɔgɔn dɛmɛ ka baara ɲɔgɔn fɛ", "Ngolo"])
265
- if "Ibrahima" in SPEAKER_NAMES:
266
- additional_examples.append(["Hakili to yɔrɔ min na, sabali bɛ yen", "Ibrahima"])
267
- if "Amara" in SPEAKER_NAMES:
268
- additional_examples.append(["Dɔnko ɲuman ye, a bɛ dɔn mɔgɔ kɔnɔ", "Amara"])
269
-
270
- base_examples.extend(additional_examples)
 
271
 
272
- return base_examples
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 dynamic examples based on available speakers
373
- current_examples = get_examples_for_available_speakers()
374
 
375
- for i, (text, speaker) in enumerate(current_examples):
376
- # Only show examples for speakers that are actually available
377
- if speaker in SPEAKER_NAMES:
378
- btn = gr.Button(f"{text[:30]}{'...' if len(text) > 30 else ''}", size="sm")
379
- btn.click(
380
- fn=lambda t=text, s=speaker: load_example(t, s),
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",