Spaces:
Running
Running
michellelychan
commited on
Commit
•
f7f6e43
1
Parent(s):
2707e70
gradio app
Browse files- app.py +32 -3
- requirements.txt +4 -0
app.py
CHANGED
@@ -1,7 +1,36 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import BarkModel, AutoProcessor
|
3 |
+
import torch
|
4 |
+
from scipy.io.wavfile import write as write_wav
|
5 |
+
import os
|
6 |
|
|
|
|
|
7 |
|
8 |
+
### if you run on GPU use the following code: ###
|
9 |
+
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
+
# model = BarkModel.from_pretrained("suno/bark-small", torch_dtype=torch.float16).to(device)
|
11 |
+
# model.enable_cpu_offload()
|
12 |
+
|
13 |
+
### if you run on CPU use the following code: ###
|
14 |
+
device = "cpu"
|
15 |
+
# load in fp16
|
16 |
+
model = BarkModel.from_pretrained("suno/bark-small").to(device)
|
17 |
+
processor = AutoProcessor.from_pretrained("suno/bark")
|
18 |
+
|
19 |
+
voice_preset = "v2/en_speaker_3"
|
20 |
+
|
21 |
+
def generate_audio(text, preset, output_file_name="bark_generation"):
|
22 |
+
file_name = output_file_name + ".wav"
|
23 |
+
inputs = processor(text, voice_preset=preset)
|
24 |
+
audio_array = model.generate(**inputs)
|
25 |
+
audio_array = audio_array.cpu().numpy().squeeze()
|
26 |
+
sample_rate = model.generation_config.sample_rate
|
27 |
+
write_wav(file_name, sample_rate, audio_array)
|
28 |
+
return file_name
|
29 |
+
|
30 |
+
|
31 |
+
#Bark Presets List
|
32 |
+
presets = ["v2/en_speaker_0","v2/en_speaker_1", "v2/en_speaker_2", "v2/en_speaker_3", "v2/en_speaker_4", "v2/en_speaker_5", "v2/en_speaker_6"]
|
33 |
+
|
34 |
+
#Gradio Interface
|
35 |
+
iface = gr.Interface(fn=generate_audio, inputs=["text", gr.components.Dropdown(choices=presets), "text"], outputs="audio")
|
36 |
iface.launch()
|
requirements.txt
CHANGED
@@ -1 +1,5 @@
|
|
1 |
gradio
|
|
|
|
|
|
|
|
|
|
1 |
gradio
|
2 |
+
transformers
|
3 |
+
torch
|
4 |
+
accelerate
|
5 |
+
scipy
|