File size: 7,404 Bytes
bb773a3
b0dcec3
5dce752
 
fd90016
56f5320
fd90016
56f5320
12672c8
 
 
 
bb773a3
 
 
 
 
56f5320
 
 
 
 
 
 
 
 
 
 
 
bb773a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56f5320
 
bb773a3
 
 
 
f374b35
 
 
12672c8
 
 
 
 
 
f374b35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d35d040
12672c8
 
2f8d592
12672c8
 
 
56f5320
 
 
 
 
b0dcec3
56f5320
 
 
 
 
d35d040
56f5320
 
 
 
 
12672c8
b0dcec3
 
56f5320
 
 
 
 
 
 
 
 
b0dcec3
 
56f5320
 
 
 
 
 
 
 
b0dcec3
bb773a3
 
a0d78cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56f5320
 
 
a0d78cf
 
 
 
 
 
 
56f5320
 
a0d78cf
 
 
 
 
 
56f5320
 
a0d78cf
 
 
 
 
56f5320
 
 
a0d78cf
 
 
 
 
 
 
 
 
56f5320
 
 
 
 
 
 
 
 
bb773a3
 
56f5320
bb773a3
 
 
 
56f5320
 
 
 
 
 
 
bb773a3
 
 
 
 
 
 
 
56f5320
bb773a3
 
 
 
56f5320
 
 
 
 
 
bb773a3
 
56f5320
bb773a3
56f5320
bb773a3
 
 
 
 
56f5320
b0dcec3
 
 
 
 
 
 
56f5320
12672c8
a0d78cf
 
56f5320
a0d78cf
 
 
56f5320
a0d78cf
56f5320
b0dcec3
 
bb773a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import gradio as gr

from config.settings import *
from data.contexts import CONTEXTS
from data.dataset_manager import load_hf_dataset
from services.annotation_service import submit_pair_annotation
from admin.admin_service import admin_login
from services.audio_service import generate_audio_pair


def update_sentence(context):
        return CONTEXTS[context]

# ============================
# SUBMIT BUTTON CONTROL
# ============================

def check_submit_ready(
        user_id,
        audio_played, 
        mos_A, 
        mos_B
):
    ready = (
        len(user_id.strip()) > 1 
        and audio_played['played'] == 1 
        and mos_A != "None" 
        and mos_B != "None"
    )
    return gr.update(interactive=ready)

def mark_audio_played():
    return {"played": 1}

# ============================
# GRADIO UI
# ============================

with gr.Blocks() as demo:

    gr.Markdown("# Audio MOS Annotation Tool")

    # --------------------------
    # USER SECTION
    # --------------------------

    audio_played = gr.State({"played": 0})

    hidden_models = gr.State()

    with gr.Row():
        user_id = gr.Textbox(label="User ID")
        gender = gr.Dropdown(["Male", "Female", "Other"], label="Gender", value="Other")

    with gr.Row():
        age_group = gr.Dropdown(
            choices=[
                "10-19",
                "20-29",
                "30-39",
                "40-49",
                "50-59",
                "60-69",
                "70+"
            ],
            label="Age Group"
        )

        native_language = gr.Textbox(
            label="Native Language"
        )

        tts_experience = gr.Dropdown(
            choices=[
                "Never",
                "Rarely",
                "Occasionally",
                "Frequently",
                "Expert"
            ],
            label="Experience with speech synthesis"
        )

        device_type = gr.Dropdown(
            choices=[
                "Headphones",
                "Earbuds",
                "Computer Speakers",
                "Smartphone Speaker"
            ],
            label="Listening Device"
        )

    with gr.Row():
        context_selector = gr.Dropdown(
            choices=list(CONTEXTS.keys()),
            value="Voice assistant",
            label="Context"
        )

        #sentence_display = gr.Textbox(
        #    value = CONTEXTS["Voice assistant"],
        #    label = "Sentence",
        #    interactive = False
        #)

        #model_selector = gr.Dropdown(
        #    choices = MODEL_OPTIONS,
        #    value = "OmniVoice",
        #    label = "Model"
        #)

        #context_selector.change(
        #    update_sentence,
        #    inputs=context_selector,
        #    outputs=sentence_display
        #)

        generate_btn = gr.Button("Generate Audio")

    #audio_player = gr.Audio(label="Generated audio")

    audio_A = gr.Audio(
        label = "Audio A"
    )

    audio_B = gr.Audio(
        label = "Audio B"
    )
    
    generate_btn.click(
        generate_audio_pair,
        inputs=context_selector,
        outputs = [
            audio_A,
            audio_B,
            audio_played,
            hidden_models
        ]
    )

    with gr.Row():
        naturalness_A = gr.Slider(
            minimum=1,
            maximum=5,
            step=1,
            value=3,
            label="Naturalness A"
        )

        intelligibility_A = gr.Slider(
            minimum=1,
            maximum=5,
            step=1,
            value=3,
            label="Intelligibility A"
        )

        context_A = gr.Slider(
            minimum=1,
            maximum=5,
            step=1,
            value=3, 
            label="Context Adequacy A"
        )

        mos_A = gr.Slider(
            minimum=1,
            maximum=5,
            step=1,
            value=3,
            label="MOS Audio A"
        )

    with gr.Row():
        naturalness_B = gr.Slider(
            minimum=1,
            maximum=5,
            step=1,
            value=3,
            label="Naturalness B"
        )

        intelligibility_B = gr.Slider(
            minimum=1,
            maximum=5,
            step=1,
            value=3,
            label="Intelligibility B"
        )

        context_B = gr.Slider(
            minimum=1,
            maximum=5,
            step=1,
            value=3, 
            label="Context Adequacy for audio B"
        )

        mos_B = gr.Slider(
            minimum=1,
            maximum=5,
            step=1,
            value=3,
            label="MOS Audio B"
        )

    with gr.Row():
        preferred_audio = gr.Radio(
            choices=[
                "Audio A",
                "Audio B",
                "No preference"
            ],
            label="Preferred Audio"
        )

        submit_btn = gr.Button("Submit Score", interactive=False)


    status = gr.Textbox(label="Status", interactive=False)


    # Mark audio as played
    audio_A.play(
        mark_audio_played,
        None,
        audio_played
    )

    audio_B.play(
        mark_audio_played,
        None,
        audio_played
    )

    # Enable submit button only when conditions are met
    user_id.change(
        check_submit_ready,
        inputs=[user_id, audio_played, mos_A, mos_B],
        outputs=submit_btn
    )
    audio_played.change(
        check_submit_ready,
        inputs=[user_id, audio_played, mos_A, mos_B],
        outputs=submit_btn
    )
    mos_A.change(
        check_submit_ready,
        inputs=[user_id, audio_played, mos_A, mos_B],
        outputs=submit_btn
    )
    mos_B.change(
        check_submit_ready,
        inputs=[user_id, audio_played, mos_A, mos_B],
        outputs=submit_btn
    )

    # Save annotation
    submit_btn.click(
        submit_pair_annotation,
        inputs=[
            user_id, 
            age_group, 
            gender, 
            native_language, 
            tts_experience, 
            device_type, 
            hidden_models,
            context_selector, 
            naturalness_A,
            intelligibility_A,
            context_A,
            mos_A,
            naturalness_B,
            intelligibility_B,
            context_B,
            mos_B,
            preferred_audio
        ],
        outputs=status
    )

    # ============================
    # ADMIN DASHBOARD
    # ============================

    gr.Markdown("## Admin Dashboard (Restricted Access)")

    with gr.Row():
        admin_password = gr.Textbox(label="Admin Password", type="password")
        admin_login_btn = gr.Button("Login")

    login_status = gr.Textbox(label="Login Status:", interactive=False)

    with gr.Column(visible=False) as admin_panel:
        gr.Markdown("### Annotation Results")
        pd_loaded=load_hf_dataset().to_pandas()
        results_table = gr.DataFrame(interactive=False, value=pd_loaded)
        pd_loaded.to_csv("annotations_export.csv", index=False)
        download_admin = gr.File(label="Download annotations.csv", value="annotations_export.csv")

    admin_login_btn.click(
        admin_login,
        inputs=admin_password,
        outputs=[admin_panel, results_table, download_admin, login_status]
    )

# ============================
# APP LAUNCH
# ============================

if __name__ == "__main__":
    demo.launch()