Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,16 +3,24 @@ from bark import SAMPLE_RATE, generate_audio, preload_models
|
|
3 |
from scipy.io.wavfile import write as write_wav
|
4 |
import tempfile
|
5 |
import torch
|
6 |
-
from numpy.core.multiarray import scalar
|
7 |
-
import numpy
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
torch.serialization.add_safe_globals([scalar, numpy.dtype])
|
12 |
|
13 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
preload_models()
|
15 |
|
|
|
|
|
|
|
16 |
def generate_speech(reference_audio, text):
|
17 |
"""
|
18 |
Generate speech audio mimicking the voice from the reference audio using Bark.
|
|
|
3 |
from scipy.io.wavfile import write as write_wav
|
4 |
import tempfile
|
5 |
import torch
|
|
|
|
|
6 |
|
7 |
+
# Save the original torch.load function
|
8 |
+
original_load = torch.load
|
|
|
9 |
|
10 |
+
# Define a custom load function that forces weights_only=False
|
11 |
+
def custom_load(*args, **kwargs):
|
12 |
+
kwargs['weights_only'] = False
|
13 |
+
return original_load(*args, **kwargs)
|
14 |
+
|
15 |
+
# Monkey-patch torch.load with the custom function
|
16 |
+
torch.load = custom_load
|
17 |
+
|
18 |
+
# Preload the models with the patched torch.load
|
19 |
preload_models()
|
20 |
|
21 |
+
# Restore the original torch.load function
|
22 |
+
torch.load = original_load
|
23 |
+
|
24 |
def generate_speech(reference_audio, text):
|
25 |
"""
|
26 |
Generate speech audio mimicking the voice from the reference audio using Bark.
|