Update barks.py
Browse files
barks.py
CHANGED
|
@@ -15,6 +15,7 @@ import warnings
|
|
| 15 |
import random
|
| 16 |
from transformers import AutoProcessor, BarkModel
|
| 17 |
from accelerate import Accelerator
|
|
|
|
| 18 |
import bitsandbytes as bnb
|
| 19 |
|
| 20 |
# Suppress warnings for cleaner output
|
|
@@ -67,8 +68,19 @@ except Exception as e:
|
|
| 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(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.")
|
|
@@ -403,6 +415,10 @@ def generate_music(instrumental_prompt: str, vocal_prompt: str, cfg_scale: float
|
|
| 403 |
finally:
|
| 404 |
memory_cleanup()
|
| 405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
# 8) CUSTOM CSS
|
| 407 |
css = """
|
| 408 |
body {
|
|
|
|
| 15 |
import random
|
| 16 |
from transformers import AutoProcessor, BarkModel
|
| 17 |
from accelerate import Accelerator
|
| 18 |
+
from transformers import BitsAndBytesConfig
|
| 19 |
import bitsandbytes as bnb
|
| 20 |
|
| 21 |
# Suppress warnings for cleaner output
|
|
|
|
| 68 |
|
| 69 |
try:
|
| 70 |
print("Loading Bark small model into GPU VRAM with 4-bit quantization...")
|
| 71 |
+
# Configure 4-bit quantization
|
| 72 |
+
quantization_config = BitsAndBytesConfig(
|
| 73 |
+
load_in_4bit=True,
|
| 74 |
+
bnb_4bit_compute_dtype=torch.float16,
|
| 75 |
+
bnb_4bit_quant_type="nf4",
|
| 76 |
+
bnb_4bit_use_double_quant=True
|
| 77 |
+
)
|
| 78 |
bark_processor = AutoProcessor.from_pretrained("suno/bark-small")
|
| 79 |
+
bark_model = BarkModel.from_pretrained(
|
| 80 |
+
"suno/bark-small",
|
| 81 |
+
quantization_config=quantization_config,
|
| 82 |
+
device_map="cuda"
|
| 83 |
+
) # Load directly to GPU with quantization
|
| 84 |
except Exception as e:
|
| 85 |
print(f"ERROR: Failed to load Bark model: {e}")
|
| 86 |
print("Ensure Bark model weights and bitsandbytes are installed.")
|
|
|
|
| 415 |
finally:
|
| 416 |
memory_cleanup()
|
| 417 |
|
| 418 |
+
# Function to clear inputs
|
| 419 |
+
def clear_inputs():
|
| 420 |
+
return "", "", 3.0, 250, 0.9, 1.0, 30, 5, 1000, 120, "none", "none", "none", "none", "none"
|
| 421 |
+
|
| 422 |
# 8) CUSTOM CSS
|
| 423 |
css = """
|
| 424 |
body {
|