sudoping01 commited on
Commit
e347941
·
verified ·
1 Parent(s): 60bcd81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -28
app.py CHANGED
@@ -36,22 +36,33 @@ def get_speakers_dict():
36
  # Use the correct new structure as shown in your example
37
  from maliba_ai.config.settings import Speakers
38
 
39
- # Create dictionary with all 10 speakers using proper syntax
40
- available_speakers = {
41
- "Bourama": Speakers.Bourama,
42
- "Adama": Speakers.Adama,
43
- "Moussa": Speakers.Moussa,
44
- "Modibo": Speakers.Modibo,
45
- "Seydou": Speakers.Seydou,
46
- "Amadou": Speakers.Amadou,
47
- "Bakary": Speakers.Bakary,
48
- "Ngolo": Speakers.Ngolo,
49
- "Ibrahima": Speakers.Ibrahima,
50
- "Amara": Speakers.Amara
 
51
  }
52
 
53
- logger.info(f"Loaded {len(available_speakers)} speakers from new structure: {list(available_speakers.keys())}")
54
- return available_speakers
 
 
 
 
 
 
 
 
 
 
55
 
56
  except Exception as e:
57
  logger.error(f"Failed to import from new settings structure: {e}")
@@ -93,7 +104,7 @@ def initialize_model_once():
93
  start_time = time.time()
94
 
95
  # Use the new import structure from the README
96
- from maliba_ai.tts.inference import BambaraTTSInference
97
 
98
  model = BambaraTTSInference()
99
  speakers = get_speakers_dict()
@@ -222,7 +233,7 @@ def get_speaker_names():
222
 
223
  SPEAKER_NAMES = get_speaker_names()
224
 
225
- # Examples with variety of lengths and speakers matched to their characteristics
226
  examples = [
227
  ["Aw ni ce", "Adama"], # Natural conversational greeting
228
  ["Mali bɛna diya kɔsɛbɛ, ka a da a kan baara bɛ ka kɛ.", "Moussa"], # Clear pronunciation for informative content
@@ -233,13 +244,33 @@ examples = [
233
  ["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
234
  ["An dɔlakelen bɛ masike bilenman don ka tɔw gɛn.", "Bourama"], # Most stable for complex statement
235
  ["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
236
- ["To tɔ nantan ni lafiya, o ka fisa ni so fa dumuniba kɛlɛma ye.", "Amadou"], # Warm and friendly voice for wisdom saying
237
- ["Mali ye jamana ɲuman ye!", "Bakary"], # Deep, authoritative tone for patriotic statement
238
- ["An ka ɲɔgɔn dɛmɛ ka baara kɛ ɲɔgɔn fɛ", "Ngolo"], # Youthful and energetic for collaboration
239
- ["Hakili to yɔrɔ min na, sabali bɛ yen", "Ibrahima"], # Calm and measured for philosophical thought
240
- ["Dɔnko ɲuman ye, a bɛ dɔn mɔgɔ kɔnɔ", "Amara"], # Melodic and smooth for poetic expression
241
  ]
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  def build_interface():
244
  """Build the Gradio interface - simplified like your old working version"""
245
 
@@ -338,12 +369,17 @@ def build_interface():
338
 
339
  gr.Markdown("**Click any example below:**")
340
 
341
- for i, (text, speaker) in enumerate(examples):
342
- btn = gr.Button(f"{text[:30]}{'...' if len(text) > 30 else ''}", size="sm")
343
- btn.click(
344
- fn=lambda t=text, s=speaker: load_example(t, s),
345
- outputs=[text_input, speaker_dropdown, use_advanced, temperature, top_k, top_p, max_tokens]
346
- )
 
 
 
 
 
347
 
348
  with gr.Accordion("About", open=False):
349
  gr.Markdown(f"""
@@ -406,7 +442,7 @@ def main():
406
  """Main function to launch the Gradio interface"""
407
  logger.info("Starting Bambara TTS Gradio interface.")
408
 
409
-
410
  interface = build_interface()
411
  interface.launch(
412
  server_name="0.0.0.0",
 
36
  # Use the correct new structure as shown in your example
37
  from maliba_ai.config.settings import Speakers
38
 
39
+ # Try to get all 10 speakers, but handle gracefully if some don't exist
40
+ available_speakers = {}
41
+ all_speakers = {
42
+ "Bourama": "Bourama",
43
+ "Adama": "Adama",
44
+ "Moussa": "Moussa",
45
+ "Modibo": "Modibo",
46
+ "Seydou": "Seydou",
47
+ "Amadou": "Amadou",
48
+ "Bakary": "Bakary",
49
+ "Ngolo": "Ngolo",
50
+ "Ibrahima": "Ibrahima",
51
+ "Amara": "Amara"
52
  }
53
 
54
+ for name, attr_name in all_speakers.items():
55
+ try:
56
+ if hasattr(Speakers, attr_name):
57
+ available_speakers[name] = getattr(Speakers, attr_name)
58
+ except:
59
+ continue
60
+
61
+ if available_speakers:
62
+ logger.info(f"Loaded {len(available_speakers)} speakers from new structure: {list(available_speakers.keys())}")
63
+ return available_speakers
64
+ else:
65
+ raise AttributeError("No speakers found in new structure")
66
 
67
  except Exception as e:
68
  logger.error(f"Failed to import from new settings structure: {e}")
 
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
 
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
  ["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 tɔ 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 kɛ ɲɔ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"""
276
 
 
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"""
 
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",