Spaces:
Runtime error
Runtime error
Paul Bauriegel
commited on
Commit
·
c55996d
1
Parent(s):
de6263f
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
import os
|
5 |
+
|
6 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
7 |
+
callback = gr.HuggingFaceDatasetSaver(HF_TOKEN, "paulbauriegel/voice-coe-demo")
|
8 |
+
|
9 |
+
sentences = \
|
10 |
+
{'en':[
|
11 |
+
"In winter, the dry leaves fly around in the air.",
|
12 |
+
"The good old man broke through the ice with his horse and fell into the cold water.",
|
13 |
+
"He always eats the eggs without salt and pepper.",
|
14 |
+
"Good to know. Now I can fix the appointment.",
|
15 |
+
"We find this approach is particularly effective at learning speech to text translation.",
|
16 |
+
"Ever wonder what your Representative has been up to?",
|
17 |
+
"The Wenker sheets are the data basis for Georg Wenker's language atlases",
|
18 |
+
"At least she gets 7000 dollars in damages"
|
19 |
+
],
|
20 |
+
'de':[
|
21 |
+
"Im Winter fliegen die trocknen Blätter durch die Luft herum.",
|
22 |
+
"Der gute alte Mann ist mit dem Pferde durch´s Eis gebrochen und in das kalte Wasser gefallen.",
|
23 |
+
"Er isst die Eier immer ohne Salz und Pfeffer.",
|
24 |
+
"Gut zu wissen. Jetzt kann ich den Termin vereinbaren.",
|
25 |
+
"Wir haben festgestellt, dass dieser Ansatz besonders effektiv beim Erlernen der Sprache-zu-Text Übersetzung
|
26 |
+
ist.",
|
27 |
+
"Haben Sie sich jemals gefragt, was Ihr Abgeordneter so treibt?",
|
28 |
+
"Die Wenkerbogen stellen die Datengrundlage für Georg Wenkers Sprachatlanten dar",
|
29 |
+
"Zumindest bekommt sie 7000 Dollar Schmerzensgeld",
|
30 |
+
]}
|
31 |
+
with gr.Blocks(title='Voice CoE Data Collection') as demo:
|
32 |
+
_ = gr.HTML('<center><h1>CoE Voice Data Collection</h1><center>')
|
33 |
+
lang = gr.Dropdown(
|
34 |
+
["de", "en"],
|
35 |
+
value='en',
|
36 |
+
interactive=True,
|
37 |
+
label="Choose your language",
|
38 |
+
)
|
39 |
+
client_ip = gr.Label("", label="User-IP", visible=False)
|
40 |
+
with gr.Row():
|
41 |
+
#outputs = gr.components.Textbox(label=)
|
42 |
+
label_0 = gr.Label(sentences['en'][0], label="")
|
43 |
+
audio_0 = gr.Audio(source="microphone", type="filepath", label="Record sample")
|
44 |
+
with gr.Row():
|
45 |
+
#outputs = gr.components.Textbox(label=)
|
46 |
+
label_1 = gr.Label(sentences['en'][1], label="")
|
47 |
+
audio_1 = gr.Audio(source="microphone", type="filepath", label="Record sample")
|
48 |
+
with gr.Row():
|
49 |
+
#outputs = gr.components.Textbox(label=)
|
50 |
+
label_2 = gr.Label(sentences['en'][2], label="")
|
51 |
+
audio_2 = gr.Audio(source="microphone", type="filepath", label="Record sample")
|
52 |
+
with gr.Row():
|
53 |
+
#outputs = gr.components.Textbox(label=)
|
54 |
+
label_3 = gr.Label(sentences['en'][3], label="")
|
55 |
+
audio_3 = gr.Audio(source="microphone", type="filepath", label="Record sample")
|
56 |
+
with gr.Row():
|
57 |
+
#outputs = gr.components.Textbox(label=)
|
58 |
+
label_4 = gr.Label(sentences['en'][4], label="")
|
59 |
+
audio_4 = gr.Audio(source="microphone", type="filepath", label="Record sample")
|
60 |
+
with gr.Row():
|
61 |
+
#outputs = gr.components.Textbox(label=)
|
62 |
+
label_5 = gr.Label(sentences['en'][5], label="")
|
63 |
+
audio_5 = gr.Audio(source="microphone", type="filepath", label="Record sample")
|
64 |
+
with gr.Row():
|
65 |
+
#outputs = gr.components.Textbox(label=)
|
66 |
+
label_6 = gr.Label(sentences['en'][6], label="")
|
67 |
+
audio_6 = gr.Audio(source="microphone", type="filepath", label="Record sample")
|
68 |
+
with gr.Row():
|
69 |
+
#outputs = gr.components.Textbox(label=)
|
70 |
+
label_7 = gr.Label(sentences['en'][7], label="")
|
71 |
+
audio_7 = gr.Audio(source="microphone", type="filepath", label="Record sample")
|
72 |
+
with gr.Row():
|
73 |
+
acc = gr.Dropdown(
|
74 |
+
["yes", "no", "maybe"],
|
75 |
+
label="Do you have an accent in the spoken language",
|
76 |
+
)
|
77 |
+
with gr.Row():
|
78 |
+
agree = gr.Checkbox(value=False, label='I agree that my data is stored and analysed by the iHub CoE Voice Team')
|
79 |
+
with gr.Row():
|
80 |
+
btn = gr.Button("Submit data")
|
81 |
+
thx = gr.HTML('') #
|
82 |
+
|
83 |
+
|
84 |
+
lang.change(lambda x: {label_0: sentences[x][0],
|
85 |
+
label_1: sentences[x][1],
|
86 |
+
label_2: sentences[x][2],
|
87 |
+
label_3: sentences[x][3],
|
88 |
+
label_4: sentences[x][4],
|
89 |
+
label_5: sentences[x][5],
|
90 |
+
label_6: sentences[x][6],
|
91 |
+
label_7: sentences[x][7], },
|
92 |
+
lang,
|
93 |
+
[label_0, label_1, label_2, label_3,
|
94 |
+
label_4, label_5, label_6, label_7])
|
95 |
+
|
96 |
+
# This needs to be called at some point prior to the first call to callback.flag()
|
97 |
+
callback.setup([client_ip, lang, audio_0, audio_1, audio_2, audio_3, audio_4, audio_5, audio_6, audio_7, acc],
|
98 |
+
"flagged_data_points")
|
99 |
+
|
100 |
+
# We can choose which components to flag -- in this case, we'll flag all of them
|
101 |
+
def submit_data(client_ip, lang, audio_0, audio_1, audio_2, audio_3, audio_4, audio_5, audio_6, audio_7, acc, agree,
|
102 |
+
request: gr.Request):
|
103 |
+
if not agree:
|
104 |
+
return '<h3>No data has been submitted</h3>'
|
105 |
+
else:
|
106 |
+
client_ip_d = {'ip': request.client.host}
|
107 |
+
callback.flag([client_ip_d, lang, audio_0, audio_1, audio_2, audio_3, audio_4, audio_5, audio_6, audio_7,
|
108 |
+
acc])
|
109 |
+
return '<h3>Thank you for submitting you data</h3>'
|
110 |
+
|
111 |
+
btn.click(submit_data,
|
112 |
+
[client_ip, lang, audio_0, audio_1, audio_2, audio_3, audio_4, audio_5, audio_6, audio_7, acc, agree],
|
113 |
+
thx,
|
114 |
+
preprocess=False)
|
115 |
+
|
116 |
+
demo.launch()
|
117 |
+
|