Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
import numpy as np
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
set_seed(0)
|
9 |
+
|
10 |
+
def _grab_best_device(use_gpu=True):
|
11 |
+
if torch.cuda.device_count() > 0 and use_gpu:
|
12 |
+
device = "cuda"
|
13 |
+
else:
|
14 |
+
device = "cpu"
|
15 |
+
return device
|
16 |
+
|
17 |
+
device = _grab_best_device()
|
18 |
+
|
19 |
+
HUB_PATH = "ylacombe/vits_vctk_welsh_male"
|
20 |
+
pipe = pipeline(HUB_PATH, device=0)
|
21 |
+
|
22 |
+
title = "# 🐶 VITS"
|
23 |
+
|
24 |
+
description = """
|
25 |
+
|
26 |
+
"""
|
27 |
+
|
28 |
+
num_speakers = pipe.model.config.num_speakers
|
29 |
+
|
30 |
+
# Inference
|
31 |
+
def generate_audio(text, spkr_id):
|
32 |
+
|
33 |
+
forward_params = {"spkr_id": spkr_id}
|
34 |
+
output = pipeline(text, forward_params=forward_params)
|
35 |
+
|
36 |
+
return (output["sampling_rate"], output["audio"].squeeze())
|
37 |
+
|
38 |
+
|
39 |
+
# Gradio blocks demo
|
40 |
+
with gr.Blocks() as demo_blocks:
|
41 |
+
gr.Markdown(title)
|
42 |
+
gr.Markdown(description)
|
43 |
+
with gr.Row():
|
44 |
+
with gr.Column():
|
45 |
+
inp_text = gr.Textbox(label="Input Text", info="What would you like bark to synthesise?")
|
46 |
+
spkr = gr.Dropdown(
|
47 |
+
[i for i in range(num_speakers)],
|
48 |
+
value=None,
|
49 |
+
label="Speaker ID",
|
50 |
+
info="Default: Unconditional Generation"
|
51 |
+
)
|
52 |
+
btn = gr.Button("Generate Audio!")
|
53 |
+
|
54 |
+
with gr.Column():
|
55 |
+
out_audio_vocos = gr.Audio(type="numpy", autoplay=False, label="Generated Audio", show_label=True)
|
56 |
+
|
57 |
+
btn.click(generate_audio, [inp_text, spk], [out_audio_vocos])
|
58 |
+
|
59 |
+
demo_blocks.queue().launch(debug=True)
|