sudoping01 commited on
Commit
2d306ed
·
verified ·
1 Parent(s): 0456d9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -38
app.py CHANGED
@@ -94,7 +94,7 @@ def get_speakers_dict():
94
 
95
  @spaces.GPU()
96
  def initialize_model_once():
97
- """Initialize model with retry logic for Unsloth compilation issues"""
98
  global _tts_model, _speakers_dict, _model_initialized, _initialization_in_progress
99
 
100
  if _model_initialized:
@@ -110,44 +110,34 @@ def initialize_model_once():
110
 
111
  _initialization_in_progress = True
112
 
113
- # Retry logic for Unsloth compilation issues
114
- max_retries = 2
115
- for attempt in range(max_retries + 1):
116
- try:
117
- logger.info(f"Initializing Bambara TTS model... (attempt {attempt + 1})")
118
- start_time = time.time()
119
-
120
- # Use the correct import path
121
- from maliba_ai.tts.inference import BambaraTTSInference
122
-
123
- model = BambaraTTSInference()
124
- speakers = get_speakers_dict()
125
-
126
- if not speakers:
127
- raise ValueError("Failed to load speakers dictionary")
128
-
129
- _tts_model = model
130
- _speakers_dict = speakers
131
- _model_initialized = True
132
-
133
- elapsed = time.time() - start_time
134
- logger.info(f"Model initialized successfully in {elapsed:.2f} seconds!")
135
-
136
- return _tts_model, _speakers_dict
137
-
138
- except Exception as e:
139
- error_msg = str(e)
140
- if "unsloth_compiled_module" in error_msg and attempt < max_retries:
141
- logger.warning(f"Unsloth compilation failed (attempt {attempt + 1}/{max_retries + 1}), retrying...")
142
- time.sleep(2) # Brief delay before retry
143
- continue
144
- else:
145
- logger.error(f"Failed to initialize model: {e}")
146
- _initialization_in_progress = False
147
- raise e
148
  finally:
149
- if not _model_initialized:
150
- _initialization_in_progress = False
151
 
152
  def validate_inputs(text, temperature, top_k, top_p, max_tokens):
153
  """Same validation as your old version"""
 
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
 
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
 
141
 
142
  def validate_inputs(text, temperature, top_k, top_p, max_tokens):
143
  """Same validation as your old version"""