Spaces:
Running
Running
eaysu
commited on
Commit
·
907a50a
1
Parent(s):
a6bbc99
app optimized
Browse files
app.py
CHANGED
@@ -1,7 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoProcessor, BarkModel
|
|
|
3 |
import scipy
|
4 |
|
|
|
|
|
|
|
5 |
# Load the Bark model and processor
|
6 |
processor = AutoProcessor.from_pretrained("suno/bark-small")
|
7 |
model = BarkModel.from_pretrained("suno/bark-small")
|
@@ -10,10 +14,13 @@ model = BarkModel.from_pretrained("suno/bark-small")
|
|
10 |
def generate_speech(text, voice_preset):
|
11 |
# Process the input text with the selected voice preset
|
12 |
inputs = processor(text, voice_preset=voice_preset)
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
17 |
return (model.generation_config.sample_rate, audio_array)
|
18 |
|
19 |
# Gradio app setup
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoProcessor, BarkModel
|
3 |
+
import torch
|
4 |
import scipy
|
5 |
|
6 |
+
# Limit CPU usage
|
7 |
+
torch.set_num_threads(1)
|
8 |
+
|
9 |
# Load the Bark model and processor
|
10 |
processor = AutoProcessor.from_pretrained("suno/bark-small")
|
11 |
model = BarkModel.from_pretrained("suno/bark-small")
|
|
|
14 |
def generate_speech(text, voice_preset):
|
15 |
# Process the input text with the selected voice preset
|
16 |
inputs = processor(text, voice_preset=voice_preset)
|
17 |
+
|
18 |
+
# Generate audio and convert to float32 early to optimize memory usage
|
19 |
+
with torch.no_grad(): # Disable gradient calculations for faster inference
|
20 |
+
audio_array = model.generate(**inputs)
|
21 |
+
audio_array = audio_array.cpu().numpy().astype('float32').squeeze() # Converting early
|
22 |
+
|
23 |
+
# Return the audio with sample rate for Gradio's audio component
|
24 |
return (model.generation_config.sample_rate, audio_array)
|
25 |
|
26 |
# Gradio app setup
|