Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,32 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
-
import
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
7 |
|
8 |
def say_something(text):
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
|
15 |
with gr.Blocks() as demo:
|
16 |
-
textBox = gr.Textbox(label="Text")
|
17 |
button = gr.Button("Generate Speech")
|
18 |
audio_output = gr.Audio(label="Generated Speech")
|
19 |
-
button.click(
|
20 |
|
21 |
|
22 |
demo.launch()
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
+
from transformers import BarkModel, AutoProcessor
|
4 |
+
import torch
|
5 |
|
6 |
+
# Desactivar paralelismo en tokenizers para evitar advertencias
|
7 |
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
8 |
+
|
9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
|
11 |
def say_something(text):
|
12 |
+
processor = AutoProcessor.from_pretrained("suno/bark-small")
|
13 |
+
|
14 |
+
model = BarkModel.from_pretrained("suno/bark-small").to(device)
|
15 |
+
|
16 |
+
inputs = processor(text)
|
17 |
+
audio_array = model.generate(**inputs)
|
18 |
+
audio_array = audio_array.cpu().numpy().squeeze()
|
19 |
+
|
20 |
+
# Devuelve el audio como un numpy array junto con el sample rate
|
21 |
+
sample_rate = model.generation_config.sample_rate
|
22 |
+
return (sample_rate, audio_array)
|
23 |
|
24 |
|
25 |
with gr.Blocks() as demo:
|
26 |
+
textBox = gr.Textbox(label="Text", value="Hello! [laugths]. This is a test!")
|
27 |
button = gr.Button("Generate Speech")
|
28 |
audio_output = gr.Audio(label="Generated Speech")
|
29 |
+
button.click(say_something, inputs=textBox, outputs=audio_output)
|
30 |
|
31 |
|
32 |
demo.launch()
|