sudoping01 commited on
Commit
2506e7b
·
verified ·
1 Parent(s): 63e4eff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import os
2
 
3
- # Set environment variables to disable compilation and optimize PyTorch
4
  os.environ["TORCHDYNAMO_DISABLE"] = "1"
5
  os.environ["TORCH_COMPILE_DISABLE"] = "1"
6
  os.environ["PYTORCH_DISABLE_CUDNN_BENCHMARK"] = "1"
@@ -13,11 +12,11 @@ import spaces
13
  import logging
14
  from huggingface_hub import login
15
 
16
- # Disable PyTorch compilation completely
17
  torch._dynamo.config.disable = True
18
  torch._dynamo.config.suppress_errors = True
19
 
20
- # Set up logging
21
  logging.basicConfig(level=logging.INFO)
22
  logger = logging.getLogger(__name__)
23
 
@@ -25,7 +24,7 @@ hf_token = os.getenv("HF_TOKEN")
25
  if hf_token:
26
  login(token=hf_token)
27
 
28
- # Global variables for model and speakers
29
  tts_model = None
30
  speakers_dict = None
31
  model_initialized = False
@@ -82,13 +81,13 @@ def validate_inputs(text, temperature, top_k, top_p, max_tokens):
82
 
83
  @spaces.GPU()
84
  def generate_speech(text, speaker_name, use_advanced, temperature, top_k, top_p, max_tokens):
85
- """Generate speech using the pre-loaded model"""
86
 
87
  if not text.strip():
88
  return None, "Please enter some Bambara text."
89
 
90
  try:
91
- # Get the initialized model and speakers
92
  tts, speakers = initialize_model()
93
 
94
  speaker = speakers[speaker_name]
@@ -122,7 +121,7 @@ def generate_speech(text, speaker_name, use_advanced, temperature, top_k, top_p,
122
  logger.error(f"Speech generation failed: {e}")
123
  return None, f"❌ Error: {str(e)}"
124
 
125
- # Define speaker names for UI
126
  SPEAKER_NAMES = ["Adame", "Moussa", "Bourama", "Modibo", "Seydou"]
127
 
128
  examples = [
@@ -130,9 +129,9 @@ examples = [
130
  ["I ni ce", "Moussa"],
131
  ["Aw ni tile", "Bourama"],
132
  ["I ka kene wa?", "Modibo"],
133
- ["Ala ka Mali suma", "Adame"],
134
  ["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"],
135
- ["Aw ni ce. Ne tɔgɔ ye Kaya Magan. Aw Sanbe Sanbe.", "Moussa"],
136
  ["An dɔlakelen bɛ masike bilenman don ka tɔw gɛn.", "Bourama"],
137
  ["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"],
138
  ]
@@ -147,8 +146,7 @@ def build_interface():
147
  Convert Bambara text to speech using AI. This model is currently experimental.
148
 
149
  **Bambara** is spoken by millions of people in Mali and West Africa.
150
-
151
- ⚡ **Note**: Model loads automatically on first use and stays loaded for optimal performance.
152
  """)
153
 
154
  with gr.Row():
@@ -227,20 +225,20 @@ def build_interface():
227
  container=False
228
  )
229
 
230
- with gr.Accordion("📚 Try These Examples", open=True):
231
  def load_example(text, speaker):
232
  return text, speaker, False, 0.8, 50, 0.9, 2048
233
 
234
  gr.Markdown("**Click any example below:**")
235
 
236
  for i, (text, speaker) in enumerate(examples):
237
- btn = gr.Button(f"🎯 {text[:30]}{'...' if len(text) > 30 else ''}", size="sm")
238
  btn.click(
239
  fn=lambda t=text, s=speaker: load_example(t, s),
240
  outputs=[text_input, speaker_dropdown, use_advanced, temperature, top_k, top_p, max_tokens]
241
  )
242
 
243
- with gr.Accordion("ℹ️ About", open=False):
244
  gr.Markdown("""
245
  **⚠️ This is an experimental Bambara TTS model.**
246
 
 
1
  import os
2
 
 
3
  os.environ["TORCHDYNAMO_DISABLE"] = "1"
4
  os.environ["TORCH_COMPILE_DISABLE"] = "1"
5
  os.environ["PYTORCH_DISABLE_CUDNN_BENCHMARK"] = "1"
 
12
  import logging
13
  from huggingface_hub import login
14
 
15
+
16
  torch._dynamo.config.disable = True
17
  torch._dynamo.config.suppress_errors = True
18
 
19
+
20
  logging.basicConfig(level=logging.INFO)
21
  logger = logging.getLogger(__name__)
22
 
 
24
  if hf_token:
25
  login(token=hf_token)
26
 
27
+
28
  tts_model = None
29
  speakers_dict = None
30
  model_initialized = False
 
81
 
82
  @spaces.GPU()
83
  def generate_speech(text, speaker_name, use_advanced, temperature, top_k, top_p, max_tokens):
84
+
85
 
86
  if not text.strip():
87
  return None, "Please enter some Bambara text."
88
 
89
  try:
90
+
91
  tts, speakers = initialize_model()
92
 
93
  speaker = speakers[speaker_name]
 
121
  logger.error(f"Speech generation failed: {e}")
122
  return None, f"❌ Error: {str(e)}"
123
 
124
+
125
  SPEAKER_NAMES = ["Adame", "Moussa", "Bourama", "Modibo", "Seydou"]
126
 
127
  examples = [
 
129
  ["I ni ce", "Moussa"],
130
  ["Aw ni tile", "Bourama"],
131
  ["I ka kene wa?", "Modibo"],
132
+ ["Lakɔli karamɔgɔw tun tɛ ka se ka sɛbɛnni kɛ ka ɲɛ walanba kan wa denmisɛnw tun tɛ se ka o sɛbɛnni ninnu ye kuma tɛ ka kalan. Denmisɛnw kɛra kunfinw ye", "Adame"],
133
  ["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"],
134
+ ["Aw ni ce. Ne tɔgɔ ye Adama. Awɔ ne ye Malien 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"],
135
  ["An dɔlakelen bɛ masike bilenman don ka tɔw gɛn.", "Bourama"],
136
  ["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"],
137
  ]
 
146
  Convert Bambara text to speech using AI. This model is currently experimental.
147
 
148
  **Bambara** is spoken by millions of people in Mali and West Africa.
149
+ .
 
150
  """)
151
 
152
  with gr.Row():
 
225
  container=False
226
  )
227
 
228
+ with gr.Accordion( Try These Examples", open=True):
229
  def load_example(text, speaker):
230
  return text, speaker, False, 0.8, 50, 0.9, 2048
231
 
232
  gr.Markdown("**Click any example below:**")
233
 
234
  for i, (text, speaker) in enumerate(examples):
235
+ btn = gr.Button(f" {text[:30]}{'...' if len(text) > 30 else ''}", size="sm")
236
  btn.click(
237
  fn=lambda t=text, s=speaker: load_example(t, s),
238
  outputs=[text_input, speaker_dropdown, use_advanced, temperature, top_k, top_p, max_tokens]
239
  )
240
 
241
+ with gr.Accordion(" About", open=False):
242
  gr.Markdown("""
243
  **⚠️ This is an experimental Bambara TTS model.**
244