Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
-
# GhostAI Music Generator Hugging Face Spaces Version
|
3 |
import os, sys, gc, time, warnings, tempfile
|
4 |
import torch, torchaudio, numpy as np, gradio as gr
|
5 |
from pydub import AudioSegment
|
6 |
from audiocraft.models import MusicGen
|
7 |
from huggingface_hub import login
|
|
|
8 |
|
9 |
warnings.filterwarnings("ignore")
|
10 |
|
@@ -16,7 +17,6 @@ login(HF_TOKEN)
|
|
16 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
17 |
print(f"Running on {device.upper()}")
|
18 |
|
19 |
-
# Fix transformers compatibility manually
|
20 |
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:128"
|
21 |
|
22 |
musicgen = MusicGen.get_pretrained("medium")
|
@@ -28,6 +28,7 @@ def clean_resources():
|
|
28 |
torch.cuda.empty_cache()
|
29 |
gc.collect()
|
30 |
|
|
|
31 |
def generate_music(prompt, cfg, top_k, top_p, temp, total_len, chunk_len, crossfade):
|
32 |
if not prompt.strip():
|
33 |
return None, "⚠️ Enter a valid prompt."
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
+
# GhostAI Music Generator Hugging Face Spaces GPU Compatible Version
|
3 |
import os, sys, gc, time, warnings, tempfile
|
4 |
import torch, torchaudio, numpy as np, gradio as gr
|
5 |
from pydub import AudioSegment
|
6 |
from audiocraft.models import MusicGen
|
7 |
from huggingface_hub import login
|
8 |
+
import spaces # Hugging Face spaces decorator
|
9 |
|
10 |
warnings.filterwarnings("ignore")
|
11 |
|
|
|
17 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
18 |
print(f"Running on {device.upper()}")
|
19 |
|
|
|
20 |
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:128"
|
21 |
|
22 |
musicgen = MusicGen.get_pretrained("medium")
|
|
|
28 |
torch.cuda.empty_cache()
|
29 |
gc.collect()
|
30 |
|
31 |
+
@spaces.GPU # <--- Required Hugging Face GPU decorator
|
32 |
def generate_music(prompt, cfg, top_k, top_p, temp, total_len, chunk_len, crossfade):
|
33 |
if not prompt.strip():
|
34 |
return None, "⚠️ Enter a valid prompt."
|