Kremon96 commited on
Commit
8ba801b
·
verified ·
1 Parent(s): 756091b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -15
app.py CHANGED
@@ -77,9 +77,13 @@ def get_available_device():
77
 
78
  # print("FISH_AE_DTYPE:", FISH_AE_DTYPE)
79
  # print("IS_ZEROGPU:", IS_ZEROGPU)
80
- # device = get_available_device()
81
  # print(f"Using device: {device}")
82
 
 
 
 
 
83
  def _safe_members(tf, prefix):
84
  if not prefix.endswith('/'):
85
  prefix += '/'
@@ -180,7 +184,7 @@ def load_models():
180
  # print(f"Loading models to device: {device}")
181
 
182
  model = load_model_from_hf(dtype=MODEL_DTYPE, compile=False, token=HF_TOKEN, device=device)
183
- fish_ae = load_fish_ae_from_hf(compile=(COMPILE_FISH_IF_NOT_ON_ZERO_GPU and not IS_ZEROGPU), dtype=FISH_AE_DTYPE, token=HF_TOKEN, device=device)
184
 
185
  pca_state = load_pca_state_from_hf(token=HF_TOKEN, device=device)
186
 
@@ -201,9 +205,9 @@ def compile_model(should_compile):
201
  """Compile the model for faster inference."""
202
  global model, model_compiled, _model_compiled
203
 
204
- # If on Zero GPU, compilation is not supported
205
- if IS_ZEROGPU:
206
- return gr.update(value=False, interactive=False), gr.update(value="⚠️ Compile disabled on Zero GPU", visible=True)
207
 
208
  if not should_compile:
209
  # User unchecked - clear status and allow toggling
@@ -221,9 +225,9 @@ def do_compile():
221
  """Actually perform the compilation by creating a separate compiled model."""
222
  global model, model_compiled, _model_compiled
223
 
224
- # Skip if on Zero GPU
225
- if IS_ZEROGPU:
226
- return gr.update(value="⚠️ Compile disabled on Zero GPU", visible=True), gr.update(interactive=False)
227
 
228
  if _model_compiled:
229
  return gr.update(value="", visible=False), gr.update(interactive=True)
@@ -324,6 +328,11 @@ def generate_audio(
324
  # Load models on first use (required for Zero GPU)
325
  load_models()
326
 
 
 
 
 
 
327
  # Choose which model to use based on compile setting
328
  global model, model_compiled
329
  active_model = model_compiled if (use_compile and model_compiled is not None) else model
@@ -1855,13 +1864,13 @@ def init_and_compile():
1855
 
1856
  # Trigger compilation automatically on page load if not on Zero GPU
1857
  # This ensures Simple mode (which defaults compile=True) gets compiled
1858
- if not IS_ZEROGPU:
1859
  # Just call do_compile directly - it will load models and compile
1860
  # Status updates will be visible in Advanced mode, hidden in Simple mode
1861
  status_update, checkbox_update = do_compile()
1862
  return session_id, status_update, checkbox_update
1863
  else:
1864
- # On Zero GPU, don't try to compile
1865
  return session_id, gr.update(), gr.update()
1866
 
1867
  SIMPLE_CSS = """
@@ -2299,13 +2308,13 @@ with gr.Blocks(title="Echo-TTS", css=LINK_CSS + SIMPLE_CSS, js=JS_CODE) as demo:
2299
  with gr.Column(scale=1, visible=False) as advanced_mode_compile_column:
2300
  compile_checkbox = gr.Checkbox(
2301
  label="Compile Model",
2302
- value=True, # Default to True in simple mode
2303
- interactive=not IS_ZEROGPU,
2304
- info="Compile disabled on Zero GPU" if IS_ZEROGPU else "~20-30% faster after initial compilation"
2305
  )
2306
  compile_status = gr.Markdown(
2307
- value="⚠️ Compile disabled on Zero GPU" if IS_ZEROGPU else "",
2308
- visible=IS_ZEROGPU
2309
  )
2310
  use_custom_shapes_checkbox = gr.Checkbox(
2311
  label="Use Custom Shapes (Advanced)",
 
77
 
78
  # print("FISH_AE_DTYPE:", FISH_AE_DTYPE)
79
  # print("IS_ZEROGPU:", IS_ZEROGPU)
80
+ device = get_available_device()
81
  # print(f"Using device: {device}")
82
 
83
+ # Определяем, доступна ли компиляция (только для CUDA и не на Zero GPU)
84
+ COMPILE_AVAILABLE = (device == 'cuda' and not IS_ZEROGPU)
85
+ # print(f"Compile available: {COMPILE_AVAILABLE}")
86
+
87
  def _safe_members(tf, prefix):
88
  if not prefix.endswith('/'):
89
  prefix += '/'
 
184
  # print(f"Loading models to device: {device}")
185
 
186
  model = load_model_from_hf(dtype=MODEL_DTYPE, compile=False, token=HF_TOKEN, device=device)
187
+ fish_ae = load_fish_ae_from_hf(compile=False, dtype=FISH_AE_DTYPE, token=HF_TOKEN, device=device)
188
 
189
  pca_state = load_pca_state_from_hf(token=HF_TOKEN, device=device)
190
 
 
205
  """Compile the model for faster inference."""
206
  global model, model_compiled, _model_compiled
207
 
208
+ # Если компиляция недоступна (CPU или Zero GPU), отключаем чекбокс
209
+ if not COMPILE_AVAILABLE:
210
+ return gr.update(value=False, interactive=False), gr.update(value="⚠️ Compile disabled on CPU/Zero GPU", visible=True)
211
 
212
  if not should_compile:
213
  # User unchecked - clear status and allow toggling
 
225
  """Actually perform the compilation by creating a separate compiled model."""
226
  global model, model_compiled, _model_compiled
227
 
228
+ # Если компиляция недоступна, пропускаем
229
+ if not COMPILE_AVAILABLE:
230
+ return gr.update(value="⚠️ Compile disabled on CPU/Zero GPU", visible=True), gr.update(interactive=False)
231
 
232
  if _model_compiled:
233
  return gr.update(value="", visible=False), gr.update(interactive=True)
 
328
  # Load models on first use (required for Zero GPU)
329
  load_models()
330
 
331
+ # Если компиляция недоступна, игнорируем флаг use_compile
332
+ if not COMPILE_AVAILABLE:
333
+ use_compile = False
334
+ # print("Compile not available on CPU/Zero GPU, using uncompiled model")
335
+
336
  # Choose which model to use based on compile setting
337
  global model, model_compiled
338
  active_model = model_compiled if (use_compile and model_compiled is not None) else model
 
1864
 
1865
  # Trigger compilation automatically on page load if not on Zero GPU
1866
  # This ensures Simple mode (which defaults compile=True) gets compiled
1867
+ if COMPILE_AVAILABLE:
1868
  # Just call do_compile directly - it will load models and compile
1869
  # Status updates will be visible in Advanced mode, hidden in Simple mode
1870
  status_update, checkbox_update = do_compile()
1871
  return session_id, status_update, checkbox_update
1872
  else:
1873
+ # On CPU or Zero GPU, don't try to compile
1874
  return session_id, gr.update(), gr.update()
1875
 
1876
  SIMPLE_CSS = """
 
2308
  with gr.Column(scale=1, visible=False) as advanced_mode_compile_column:
2309
  compile_checkbox = gr.Checkbox(
2310
  label="Compile Model",
2311
+ value=False, # По умолчанию выключено для CPU
2312
+ interactive=COMPILE_AVAILABLE,
2313
+ info="Compile disabled on CPU/Zero GPU" if not COMPILE_AVAILABLE else "~20-30% faster after initial compilation"
2314
  )
2315
  compile_status = gr.Markdown(
2316
+ value="⚠️ Compile disabled on CPU/Zero GPU" if not COMPILE_AVAILABLE else "",
2317
+ visible=not COMPILE_AVAILABLE
2318
  )
2319
  use_custom_shapes_checkbox = gr.Checkbox(
2320
  label="Use Custom Shapes (Advanced)",