Spaces:
Paused
Paused
2b commited on
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -29,6 +29,7 @@ _TEXT_TO_AUDIO_PIPELINE: Any | None = None
|
|
| 29 |
_PIPELINE_MODEL_ID: str | None = None
|
| 30 |
_PIPELINE_DEVICE: str = "cpu"
|
| 31 |
_DEPENDENCIES_READY = False
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
def write_dummy_wav(path: Path, seed: int, duration: float = 2.5, sample_rate: int = 44100) -> None:
|
|
@@ -99,11 +100,12 @@ def get_text_to_audio_pipeline(model_id: str):
|
|
| 99 |
|
| 100 |
ensure_runtime_dependencies()
|
| 101 |
|
| 102 |
-
import torch
|
| 103 |
from transformers import pipeline
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
| 107 |
_TEXT_TO_AUDIO_PIPELINE = pipeline(task="text-to-audio", model=model_id, device=device)
|
| 108 |
_PIPELINE_MODEL_ID = model_id
|
| 109 |
return _TEXT_TO_AUDIO_PIPELINE
|
|
@@ -159,10 +161,7 @@ def generate_music(
|
|
| 159 |
"max_new_tokens": max_new_tokens,
|
| 160 |
}
|
| 161 |
# Keep deterministic output across calls with the same seed.
|
| 162 |
-
|
| 163 |
-
generate_kwargs["generator"] = torch.Generator("cuda").manual_seed(seed)
|
| 164 |
-
else:
|
| 165 |
-
generate_kwargs["generator"] = torch.Generator().manual_seed(seed)
|
| 166 |
|
| 167 |
result = pipe(prompt, generate_kwargs=generate_kwargs)
|
| 168 |
audio = np.asarray(result["audio"], dtype=np.float32)
|
|
|
|
| 29 |
_PIPELINE_MODEL_ID: str | None = None
|
| 30 |
_PIPELINE_DEVICE: str = "cpu"
|
| 31 |
_DEPENDENCIES_READY = False
|
| 32 |
+
FORCE_CPU = True
|
| 33 |
|
| 34 |
|
| 35 |
def write_dummy_wav(path: Path, seed: int, duration: float = 2.5, sample_rate: int = 44100) -> None:
|
|
|
|
| 100 |
|
| 101 |
ensure_runtime_dependencies()
|
| 102 |
|
|
|
|
| 103 |
from transformers import pipeline
|
| 104 |
|
| 105 |
+
# ZeroGPU environments can report CUDA availability while blocking low-level CUDA init.
|
| 106 |
+
# CPU mode is slower but stable and avoids intermittent emulation/runtime crashes.
|
| 107 |
+
device = -1 if FORCE_CPU else 0
|
| 108 |
+
_PIPELINE_DEVICE = "cpu" if device < 0 else "cuda:0"
|
| 109 |
_TEXT_TO_AUDIO_PIPELINE = pipeline(task="text-to-audio", model=model_id, device=device)
|
| 110 |
_PIPELINE_MODEL_ID = model_id
|
| 111 |
return _TEXT_TO_AUDIO_PIPELINE
|
|
|
|
| 161 |
"max_new_tokens": max_new_tokens,
|
| 162 |
}
|
| 163 |
# Keep deterministic output across calls with the same seed.
|
| 164 |
+
generate_kwargs["generator"] = torch.Generator().manual_seed(seed)
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
result = pipe(prompt, generate_kwargs=generate_kwargs)
|
| 167 |
audio = np.asarray(result["audio"], dtype=np.float32)
|