sudoping01 commited on
Commit
0c96c25
Β·
verified Β·
1 Parent(s): aa84c77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -55
app.py CHANGED
@@ -24,67 +24,38 @@ hf_token = os.getenv("HF_TOKEN")
24
  if hf_token:
25
  login(token=hf_token)
26
 
27
- # Global variables for model caching (like your old working version)
28
  _tts_model = None
29
  _speakers_dict = None
30
  _model_initialized = False
31
  _initialization_in_progress = False
32
 
33
  def get_speakers_dict():
34
- """Get speakers dictionary using the correct new SDK structure"""
35
  try:
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}")
69
- # Fallback to old structure if new one fails
70
- try:
71
- from maliba_ai.config.speakers import Adame, Moussa, Bourama, Modibo, Seydou, Amadou, Bakary, Ngolo, Ibrahima, Amara
72
- logger.info("Using fallback old speaker structure")
73
- return {
74
- "Adama": Adame,
75
- "Moussa": Moussa,
76
- "Bourama": Bourama,
77
- "Modibo": Modibo,
78
- "Seydou": Seydou,
79
- "Amadou": Amadou,
80
- "Bakary": Bakary,
81
- "Ngolo": Ngolo,
82
- "Ibrahima": Ibrahima,
83
- "Amara": Amara
84
- }
85
- except Exception as e2:
86
- logger.error(f"Failed to import speakers: {e2}")
87
- return {}
88
 
89
  @spaces.GPU()
90
  def initialize_model_once():
@@ -108,8 +79,8 @@ def initialize_model_once():
108
  logger.info("Initializing Bambara TTS model...")
109
  start_time = time.time()
110
 
111
- # Use the new import structure from the README
112
- from maliba_ai.tts import BambaraTTSInference
113
 
114
  model = BambaraTTSInference()
115
  speakers = get_speakers_dict()
@@ -288,9 +259,9 @@ def build_interface():
288
  gr.Markdown("""
289
  # 🎀 Bambara Text-to-Speech
290
 
291
- **Powered by MALIBA-AI**
292
 
293
- Convert Bambara text to speech using our state-of-the-art TTS model.
294
 
295
  **Bambara** is spoken by millions of people in Mali and West Africa.
296
  """)
@@ -363,7 +334,7 @@ def build_interface():
363
  label="Generated Speech",
364
  type="numpy",
365
  interactive=False,
366
- format="wav" # Specify WAV format to help with conversion
367
  )
368
 
369
  status_output = gr.Textbox(
@@ -437,8 +408,7 @@ def build_interface():
437
  def main():
438
  """Main function to launch the Gradio interface"""
439
  logger.info("Starting Bambara TTS Gradio interface.")
440
-
441
- # DO NOT preload - let it initialize on first request only (like your working version)
442
  interface = build_interface()
443
  interface.launch(
444
  server_name="0.0.0.0",
 
24
  if hf_token:
25
  login(token=hf_token)
26
 
27
+ # Global variables for model caching
28
  _tts_model = None
29
  _speakers_dict = None
30
  _model_initialized = False
31
  _initialization_in_progress = False
32
 
33
  def get_speakers_dict():
34
+ """Get speakers dictionary using the correct SDK structure"""
35
  try:
36
+ # Import the Speakers class (not individual speakers)
37
  from maliba_ai.config.settings import Speakers
38
 
39
+ # Access all 10 speakers through the Speakers class
40
+ speakers_dict = {
41
+ "Adama": Speakers.Adama,
42
+ "Moussa": Speakers.Moussa,
43
+ "Bourama": Speakers.Bourama,
44
+ "Modibo": Speakers.Modibo,
45
+ "Seydou": Speakers.Seydou,
46
+ "Amadou": Speakers.Amadou,
47
+ "Bakary": Speakers.Bakary,
48
+ "Ngolo": Speakers.Ngolo,
49
+ "Amara": Speakers.Amara,
50
+ "Ibrahima": Speakers.Ibrahima
 
51
  }
52
 
53
+ logger.info(f"🎀 Successfully loaded {len(speakers_dict)} speakers: {list(speakers_dict.keys())}")
54
+ return speakers_dict
 
 
 
 
55
 
 
 
 
 
 
 
56
  except Exception as e:
57
+ logger.error(f"❌ Failed to import Speakers class: {e}")
58
+ return {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  @spaces.GPU()
61
  def initialize_model_once():
 
79
  logger.info("Initializing Bambara TTS model...")
80
  start_time = time.time()
81
 
82
+ # Use the correct import path
83
+ from maliba_ai.tts.inference import BambaraTTSInference
84
 
85
  model = BambaraTTSInference()
86
  speakers = get_speakers_dict()
 
259
  gr.Markdown("""
260
  # 🎀 Bambara Text-to-Speech
261
 
262
+ **Powered by MALIBA-AI** | *First Open-Source Bambara TTS*
263
 
264
+ Convert Bambara text to natural-sounding speech using our state-of-the-art neural TTS system.
265
 
266
  **Bambara** is spoken by millions of people in Mali and West Africa.
267
  """)
 
334
  label="Generated Speech",
335
  type="numpy",
336
  interactive=False,
337
+ format="wav"
338
  )
339
 
340
  status_output = gr.Textbox(
 
408
  def main():
409
  """Main function to launch the Gradio interface"""
410
  logger.info("Starting Bambara TTS Gradio interface.")
411
+
 
412
  interface = build_interface()
413
  interface.launch(
414
  server_name="0.0.0.0",