sudoping01 commited on
Commit
be36062
Β·
verified Β·
1 Parent(s): 2d306ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -35
app.py CHANGED
@@ -25,21 +25,6 @@ if is_restricted_environment():
25
  else:
26
  print("πŸ”§ Local environment detected - Unsloth optimizations enabled")
27
 
28
- # Check if we're in ZeroGPU or similar restricted environment
29
- def is_restricted_environment():
30
- return (
31
- os.getenv("ZERO_GPU") or
32
- "zero" in str(os.getenv("SPACE_ID", "")).lower() or
33
- os.getenv("SPACES_ZERO_GPU")
34
- )
35
-
36
- # Disable Unsloth optimizations in restricted environments
37
- if is_restricted_environment():
38
- os.environ["UNSLOTH_DISABLE"] = "1"
39
- os.environ["DISABLE_UNSLOTH"] = "1"
40
- os.environ["UNSLOTH_IGNORE_ERRORS"] = "1"
41
- print("πŸš€ ZeroGPU detected - Unsloth optimizations disabled for compatibility")
42
-
43
  import torch
44
  import gradio as gr
45
  import numpy as np
@@ -94,7 +79,7 @@ def get_speakers_dict():
94
 
95
  @spaces.GPU()
96
  def initialize_model_once():
97
- """Initialize model exactly like your old working version"""
98
  global _tts_model, _speakers_dict, _model_initialized, _initialization_in_progress
99
 
100
  if _model_initialized:
@@ -110,31 +95,40 @@ def initialize_model_once():
110
 
111
  _initialization_in_progress = True
112
 
 
 
 
113
  try:
114
  logger.info("Initializing Bambara TTS model...")
115
  start_time = time.time()
116
 
117
- # Use the correct import path
118
  from maliba_ai.tts.inference import BambaraTTSInference
119
 
120
- model = BambaraTTSInference()
121
- speakers = get_speakers_dict()
122
-
123
- if not speakers:
124
- raise ValueError("Failed to load speakers dictionary")
125
-
126
- _tts_model = model
127
- _speakers_dict = speakers
128
- _model_initialized = True
129
-
130
- elapsed = time.time() - start_time
131
- logger.info(f"Model initialized successfully in {elapsed:.2f} seconds!")
132
-
133
- return _tts_model, _speakers_dict
134
-
 
 
 
 
 
 
 
 
135
  except Exception as e:
136
- logger.error(f"Failed to initialize model: {e}")
137
- _initialization_in_progress = False
138
  raise e
139
  finally:
140
  _initialization_in_progress = False
@@ -406,7 +400,7 @@ def build_interface():
406
  - **πŸ“± Usage**: Educational, accessibility, and cultural preservation
407
 
408
  ### 🎭 Available Speakers:
409
- {', '.join(SPEAKER_NAMES)}
410
 
411
  **License**: Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0)
412
 
 
25
  else:
26
  print("πŸ”§ Local environment detected - Unsloth optimizations enabled")
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  import torch
29
  import gradio as gr
30
  import numpy as np
 
79
 
80
  @spaces.GPU()
81
  def initialize_model_once():
82
+ """Initialize model with retry logic for Unsloth failures"""
83
  global _tts_model, _speakers_dict, _model_initialized, _initialization_in_progress
84
 
85
  if _model_initialized:
 
95
 
96
  _initialization_in_progress = True
97
 
98
+ max_retries = 2
99
+ retry_delay = 5 # seconds
100
+
101
  try:
102
  logger.info("Initializing Bambara TTS model...")
103
  start_time = time.time()
104
 
 
105
  from maliba_ai.tts.inference import BambaraTTSInference
106
 
107
+ for attempt in range(max_retries):
108
+ try:
109
+ model = BambaraTTSInference()
110
+ speakers = get_speakers_dict()
111
+
112
+ if not speakers:
113
+ raise ValueError("Failed to load speakers dictionary")
114
+
115
+ _tts_model = model
116
+ _speakers_dict = speakers
117
+ _model_initialized = True
118
+
119
+ elapsed = time.time() - start_time
120
+ logger.info(f"Model initialized successfully in {elapsed:.2f} seconds!")
121
+ return _tts_model, _speakers_dict
122
+
123
+ except Exception as e:
124
+ if "unsloth_compiled_module_qwen2" in str(e) and attempt < max_retries - 1:
125
+ logger.warning(f"Unsloth compilation failed, retrying in {retry_delay} seconds... (attempt {attempt + 1}/{max_retries})")
126
+ time.sleep(retry_delay)
127
+ else:
128
+ raise e
129
+
130
  except Exception as e:
131
+ logger.error(f"Failed to initialize model after {max_retries} attempts: {e}")
 
132
  raise e
133
  finally:
134
  _initialization_in_progress = False
 
400
  - **πŸ“± Usage**: Educational, accessibility, and cultural preservation
401
 
402
  ### 🎭 Available Speakers:
403
+ {ettes.join(SPEAKER_NAMES)}
404
 
405
  **License**: Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0)
406