Spaces:
Running on Zero
Running on Zero
Fix ZeroGPU CUDA support for V3 demo
Browse files- app.py +15 -5
- requirements.txt +5 -2
app.py
CHANGED
|
@@ -6,6 +6,8 @@ import gradio as gr
|
|
| 6 |
import spaces
|
| 7 |
|
| 8 |
MODEL = None
|
|
|
|
|
|
|
| 9 |
|
| 10 |
DEFAULT_CONFIG = {
|
| 11 |
"audio": 'https://storage.googleapis.com/chatterbox-demo-samples/mtl_prompts/en_f1.flac',
|
|
@@ -40,9 +42,15 @@ def default_text_for_ui():
|
|
| 40 |
def get_or_load_model():
|
| 41 |
global MODEL
|
| 42 |
if MODEL is None:
|
| 43 |
-
print("Model not loaded, initializing on
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
return MODEL
|
| 47 |
|
| 48 |
|
|
@@ -66,9 +74,8 @@ def generate_tts_audio(
|
|
| 66 |
cfgw_input: float = 0.5,
|
| 67 |
):
|
| 68 |
"""Generate speech from text with optional reference audio styling."""
|
| 69 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 70 |
current_model = get_or_load_model()
|
| 71 |
-
current_model.
|
| 72 |
if seed_num_input != 0:
|
| 73 |
set_seed(int(seed_num_input), device)
|
| 74 |
chosen_prompt = audio_prompt_path_input or default_audio_for_ui()
|
|
@@ -86,6 +93,9 @@ def generate_tts_audio(
|
|
| 86 |
return (current_model.sr, wav.squeeze(0).cpu().numpy())
|
| 87 |
|
| 88 |
|
|
|
|
|
|
|
|
|
|
| 89 |
with gr.Blocks() as demo:
|
| 90 |
gr.Markdown(
|
| 91 |
"""
|
|
|
|
| 6 |
import spaces
|
| 7 |
|
| 8 |
MODEL = None
|
| 9 |
+
# ZeroGPU supports CUDA placement at module load time via CUDA emulation.
|
| 10 |
+
TARGET_DEVICE = "cuda"
|
| 11 |
|
| 12 |
DEFAULT_CONFIG = {
|
| 13 |
"audio": 'https://storage.googleapis.com/chatterbox-demo-samples/mtl_prompts/en_f1.flac',
|
|
|
|
| 42 |
def get_or_load_model():
|
| 43 |
global MODEL
|
| 44 |
if MODEL is None:
|
| 45 |
+
print(f"Model not loaded, initializing on {TARGET_DEVICE}...")
|
| 46 |
+
try:
|
| 47 |
+
MODEL = ChatterboxTTS.from_pretrained(TARGET_DEVICE)
|
| 48 |
+
except Exception as exc:
|
| 49 |
+
if TARGET_DEVICE != "cuda":
|
| 50 |
+
raise
|
| 51 |
+
print(f"CUDA model initialization failed, falling back to CPU: {exc}")
|
| 52 |
+
MODEL = ChatterboxTTS.from_pretrained("cpu")
|
| 53 |
+
print(f"Model loaded on {MODEL.device}.")
|
| 54 |
return MODEL
|
| 55 |
|
| 56 |
|
|
|
|
| 74 |
cfgw_input: float = 0.5,
|
| 75 |
):
|
| 76 |
"""Generate speech from text with optional reference audio styling."""
|
|
|
|
| 77 |
current_model = get_or_load_model()
|
| 78 |
+
device = current_model.device
|
| 79 |
if seed_num_input != 0:
|
| 80 |
set_seed(int(seed_num_input), device)
|
| 81 |
chosen_prompt = audio_prompt_path_input or default_audio_for_ui()
|
|
|
|
| 93 |
return (current_model.sr, wav.squeeze(0).cpu().numpy())
|
| 94 |
|
| 95 |
|
| 96 |
+
get_or_load_model()
|
| 97 |
+
|
| 98 |
+
|
| 99 |
with gr.Blocks() as demo:
|
| 100 |
gr.Markdown(
|
| 101 |
"""
|
requirements.txt
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
numpy==1.26.0
|
| 3 |
resampy==0.4.3
|
| 4 |
librosa==0.10.0
|
| 5 |
s3tokenizer
|
| 6 |
-
torchaudio<2.8
|
| 7 |
|
| 8 |
transformers==4.46.3
|
| 9 |
diffusers==0.29.0
|
|
@@ -11,4 +14,4 @@ omegaconf==2.3.0
|
|
| 11 |
resemble-perth==1.0.1
|
| 12 |
silero-vad==5.1.2
|
| 13 |
conformer==0.3.2
|
| 14 |
-
safetensors
|
|
|
|
| 1 |
+
--extra-index-url https://download.pytorch.org/whl/cu128
|
| 2 |
+
torch==2.8.0
|
| 3 |
+
torchaudio==2.8.0
|
| 4 |
+
|
| 5 |
gradio
|
| 6 |
numpy==1.26.0
|
| 7 |
resampy==0.4.3
|
| 8 |
librosa==0.10.0
|
| 9 |
s3tokenizer
|
|
|
|
| 10 |
|
| 11 |
transformers==4.46.3
|
| 12 |
diffusers==0.29.0
|
|
|
|
| 14 |
resemble-perth==1.0.1
|
| 15 |
silero-vad==5.1.2
|
| 16 |
conformer==0.3.2
|
| 17 |
+
safetensors
|