Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
mrfakename
commited on
Commit
•
18d89f0
1
Parent(s):
29cc87b
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
DESCR = """
|
2 |
+
# TTS Arena
|
3 |
+
|
4 |
+
Vote on different speech synthesis models!
|
5 |
+
|
6 |
+
## Instructions
|
7 |
+
|
8 |
+
* Listen to two anonymous models
|
9 |
+
* Vote on which one is more natural and realistic
|
10 |
+
* If there's a tie, click Skip
|
11 |
+
|
12 |
+
*IMPORTANT: Do not only rank the outputs based on naturalness. Also rank based on intelligibility (can you actually tell what they're saying?) and other factors (does it sound like a human?).*
|
13 |
+
|
14 |
+
**When you're ready to begin, click the Start button below!** The model names will be revealed once you vote.
|
15 |
+
""".strip()
|
16 |
+
import gradio as gr
|
17 |
+
import random
|
18 |
+
import os
|
19 |
+
from datasets import load_dataset
|
20 |
+
dataset = load_dataset("ttseval/tts-arena", token=os.getenv('HF_TOKEN'))
|
21 |
+
theme = gr.themes.Base(
|
22 |
+
font=[gr.themes.GoogleFont('Libre Franklin'), gr.themes.GoogleFont('Public Sans'), 'system-ui', 'sans-serif'],
|
23 |
+
)
|
24 |
+
model_names = {
|
25 |
+
'styletts2': 'StyleTTS 2',
|
26 |
+
'tacotron': 'Tacotron',
|
27 |
+
'speedyspeech': 'Speedy Speech',
|
28 |
+
'overflow': 'Overflow TTS',
|
29 |
+
'vits': 'VITS',
|
30 |
+
'vitsneon': 'VITS Neon',
|
31 |
+
'neuralhmm': 'Neural HMM',
|
32 |
+
'glow': 'Glow TTS',
|
33 |
+
'fastpitch': 'FastPitch',
|
34 |
+
}
|
35 |
+
def get_random_split(existing_split=None):
|
36 |
+
choice = random.choice(list(dataset.keys()))
|
37 |
+
if existing_split and choice == existing_split:
|
38 |
+
return get_random_split(choice)
|
39 |
+
else:
|
40 |
+
return choice
|
41 |
+
def get_random_splits():
|
42 |
+
choice1 = get_random_split()
|
43 |
+
choice2 = get_random_split(choice1)
|
44 |
+
return (choice1, choice2)
|
45 |
+
def a_is_better(model1, model2):
|
46 |
+
chosen_model = model1
|
47 |
+
print(chosen_model)
|
48 |
+
return reload(model1, model2)
|
49 |
+
def b_is_better(model1, model2):
|
50 |
+
chosen_model = model2
|
51 |
+
print(chosen_model)
|
52 |
+
return reload(model1, model2)
|
53 |
+
def reload(chosenmodel1=None, chosenmodel2=None):
|
54 |
+
# Select random splits
|
55 |
+
split1, split2 = get_random_splits()
|
56 |
+
d1, d2 = (dataset[split1], dataset[split2])
|
57 |
+
choice1, choice2 = (d1.shuffle()[0]['audio'], d2.shuffle()[0]['audio'])
|
58 |
+
if split1 in model_names:
|
59 |
+
split1 = model_names[split1]
|
60 |
+
if split2 in model_names:
|
61 |
+
split2 = model_names[split2]
|
62 |
+
out = [
|
63 |
+
(choice1['sampling_rate'], choice1['array']),
|
64 |
+
(choice2['sampling_rate'], choice2['array']),
|
65 |
+
split1,
|
66 |
+
split2
|
67 |
+
]
|
68 |
+
if chosenmodel1: out.append(f'This model was {chosenmodel1}')
|
69 |
+
if chosenmodel2: out.append(f'This model was {chosenmodel2}')
|
70 |
+
return out
|
71 |
+
with gr.Blocks(theme=theme) as demo:
|
72 |
+
# with gr.Blocks() as demo:
|
73 |
+
gr.Markdown(DESCR)
|
74 |
+
with gr.Row():
|
75 |
+
gr.HTML('<div align="left"><h3>Model A</h3></div>')
|
76 |
+
gr.HTML('<div align="right"><h3>Model B</h3></div>')
|
77 |
+
model1 = gr.Textbox(interactive=False, visible=False)
|
78 |
+
model2 = gr.Textbox(interactive=False, visible=False)
|
79 |
+
with gr.Group():
|
80 |
+
with gr.Row():
|
81 |
+
prevmodel1 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model A")
|
82 |
+
prevmodel2 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model B", text_align="right")
|
83 |
+
with gr.Row():
|
84 |
+
aud1 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
|
85 |
+
aud2 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
|
86 |
+
with gr.Row():
|
87 |
+
abetter = gr.Button("A is Better", scale=3)
|
88 |
+
skipbtn = gr.Button("Skip", scale=1)
|
89 |
+
bbetter = gr.Button("B is Better", scale=3)
|
90 |
+
outputs = [aud1, aud2, model1, model2, prevmodel1, prevmodel2]
|
91 |
+
abetter.click(a_is_better, outputs=outputs, inputs=[model1, model2])
|
92 |
+
bbetter.click(b_is_better, outputs=outputs, inputs=[model1, model2])
|
93 |
+
skipbtn.click(b_is_better, outputs=outputs, inputs=[model1, model2])
|
94 |
+
demo.load(reload, outputs=[aud1, aud2, model1, model2])
|
95 |
+
demo.queue(api_open=False).launch(show_api=False)
|