ghostai1 commited on
Commit
105d56f
·
verified ·
1 Parent(s): e3ef1a3

Update barks.py

Browse files
Files changed (1) hide show
  1. barks.py +5 -13
barks.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import os
2
  import torch
3
  import torchaudio
@@ -65,9 +66,9 @@ except Exception as e:
65
  sys.exit(1)
66
 
67
  try:
68
- print("Loading Bark small model into system RAM with 4-bit quantization...")
69
  bark_processor = AutoProcessor.from_pretrained("suno/bark-small")
70
- bark_model = BarkModel.from_pretrained("suno/bark-small", load_in_4bit=True, device_map="cpu") # Quantize and offload to CPU
71
  except Exception as e:
72
  print(f"ERROR: Failed to load Bark model: {e}")
73
  print("Ensure Bark model weights and bitsandbytes are installed.")
@@ -270,10 +271,7 @@ def generate_vocals(vocal_prompt: str, total_duration: int):
270
 
271
  try:
272
  print("Generating vocals with Bark...")
273
- # Move Bark model to GPU
274
- bark_model = bark_model.to("cuda")
275
-
276
- # Process vocal prompt
277
  inputs = bark_processor(vocal_prompt, return_tensors="pt").to("cuda")
278
 
279
  # Generate vocals with mixed precision
@@ -293,8 +291,6 @@ def generate_vocals(vocal_prompt: str, total_duration: int):
293
  if len(vocal_segment) < total_duration * 1000:
294
  vocal_segment = vocal_segment + AudioSegment.silent(duration=(total_duration * 1000 - len(vocal_segment)))
295
 
296
- # Move Bark model back to CPU
297
- bark_model = bark_model.to("cpu")
298
  memory_cleanup()
299
 
300
  return vocal_segment, "✅ Vocals generated successfully."
@@ -407,10 +403,6 @@ def generate_music(instrumental_prompt: str, vocal_prompt: str, cfg_scale: float
407
  finally:
408
  memory_cleanup()
409
 
410
- # Function to clear inputs
411
- def clear_inputs():
412
- return "", "", 3.0, 250, 0.9, 1.0, 30, 5, 1000, 120, "none", "none", "none", "none", "none"
413
-
414
  # 8) CUSTOM CSS
415
  css = """
416
  body {
@@ -682,4 +674,4 @@ try:
682
  fastapi_app.redoc_url = None
683
  fastapi_app.openapi_url = None
684
  except Exception:
685
- pass
 
1
+
2
  import os
3
  import torch
4
  import torchaudio
 
66
  sys.exit(1)
67
 
68
  try:
69
+ print("Loading Bark small model into GPU VRAM with 4-bit quantization...")
70
  bark_processor = AutoProcessor.from_pretrained("suno/bark-small")
71
+ bark_model = BarkModel.from_pretrained("suno/bark-small", load_in_4bit=True, device_map="cuda") # Load directly to GPU with quantization
72
  except Exception as e:
73
  print(f"ERROR: Failed to load Bark model: {e}")
74
  print("Ensure Bark model weights and bitsandbytes are installed.")
 
271
 
272
  try:
273
  print("Generating vocals with Bark...")
274
+ # Process vocal prompt, ensuring inputs are on cuda
 
 
 
275
  inputs = bark_processor(vocal_prompt, return_tensors="pt").to("cuda")
276
 
277
  # Generate vocals with mixed precision
 
291
  if len(vocal_segment) < total_duration * 1000:
292
  vocal_segment = vocal_segment + AudioSegment.silent(duration=(total_duration * 1000 - len(vocal_segment)))
293
 
 
 
294
  memory_cleanup()
295
 
296
  return vocal_segment, "✅ Vocals generated successfully."
 
403
  finally:
404
  memory_cleanup()
405
 
 
 
 
 
406
  # 8) CUSTOM CSS
407
  css = """
408
  body {
 
674
  fastapi_app.redoc_url = None
675
  fastapi_app.openapi_url = None
676
  except Exception:
677
+ pass