Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,7 @@ from audiocraft.models import MusicGen
|
|
12 |
from torch.cuda.amp import autocast
|
13 |
import warnings
|
14 |
import random
|
|
|
15 |
|
16 |
# Suppress warnings for cleaner output
|
17 |
warnings.filterwarnings("ignore")
|
@@ -19,6 +20,17 @@ warnings.filterwarnings("ignore")
|
|
19 |
# Set PYTORCH_CUDA_ALLOC_CONF to manage memory fragmentation
|
20 |
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:128"
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# Check critical dependencies
|
23 |
if np.__version__ != "1.23.5":
|
24 |
print(f"WARNING: NumPy version {np.__version__} is being used. Tested with numpy==1.23.5.")
|
@@ -40,20 +52,15 @@ torch.cuda.synchronize()
|
|
40 |
|
41 |
# 2) LOAD MUSICGEN INTO VRAM
|
42 |
try:
|
43 |
-
print("Loading MusicGen medium model
|
44 |
-
|
45 |
-
if not os.path.exists(local_model_path):
|
46 |
-
print(f"ERROR: Local model path {local_model_path} does not exist.")
|
47 |
-
print("Please download the MusicGen medium model weights and place them in the correct directory.")
|
48 |
-
sys.exit(1)
|
49 |
-
musicgen_model = MusicGen.get_pretrained(local_model_path, device=device)
|
50 |
musicgen_model.set_generation_params(
|
51 |
duration=10, # Default chunk duration
|
52 |
two_step_cfg=False # Disable two-step CFG for stability
|
53 |
)
|
54 |
except Exception as e:
|
55 |
print(f"ERROR: Failed to load MusicGen model: {e}")
|
56 |
-
print("Ensure
|
57 |
sys.exit(1)
|
58 |
|
59 |
# 3) RESOURCE MONITORING FUNCTION
|
|
|
12 |
from torch.cuda.amp import autocast
|
13 |
import warnings
|
14 |
import random
|
15 |
+
from huggingface_hub import login
|
16 |
|
17 |
# Suppress warnings for cleaner output
|
18 |
warnings.filterwarnings("ignore")
|
|
|
20 |
# Set PYTORCH_CUDA_ALLOC_CONF to manage memory fragmentation
|
21 |
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:128"
|
22 |
|
23 |
+
# Authenticate with Hugging Face
|
24 |
+
hf_token = os.getenv("HF_TOKEN")
|
25 |
+
if not hf_token:
|
26 |
+
print("ERROR: HF_TOKEN environment variable not set. Please set it in the Hugging Face Space settings.")
|
27 |
+
sys.exit(1)
|
28 |
+
try:
|
29 |
+
login(hf_token)
|
30 |
+
except Exception as e:
|
31 |
+
print(f"ERROR: Failed to authenticate with Hugging Face: {e}")
|
32 |
+
sys.exit(1)
|
33 |
+
|
34 |
# Check critical dependencies
|
35 |
if np.__version__ != "1.23.5":
|
36 |
print(f"WARNING: NumPy version {np.__version__} is being used. Tested with numpy==1.23.5.")
|
|
|
52 |
|
53 |
# 2) LOAD MUSICGEN INTO VRAM
|
54 |
try:
|
55 |
+
print("Loading MusicGen medium model from Hugging Face...")
|
56 |
+
musicgen_model = MusicGen.get_pretrained("facebook/musicgen-medium", device=device)
|
|
|
|
|
|
|
|
|
|
|
57 |
musicgen_model.set_generation_params(
|
58 |
duration=10, # Default chunk duration
|
59 |
two_step_cfg=False # Disable two-step CFG for stability
|
60 |
)
|
61 |
except Exception as e:
|
62 |
print(f"ERROR: Failed to load MusicGen model: {e}")
|
63 |
+
print("Ensure you have access to facebook/musicgen-medium and a valid HF_TOKEN.")
|
64 |
sys.exit(1)
|
65 |
|
66 |
# 3) RESOURCE MONITORING FUNCTION
|