File size: 8,332 Bytes
8ae1600
 
 
 
db710bd
63fb484
eaf8706
 
e65f31d
578ad69
 
 
e65f31d
bb77d44
 
06b95aa
578ad69
626626c
578ad69
 
 
 
 
 
626626c
 
06b95aa
d8e60e3
06b95aa
 
61ec2c0
 
 
0edd040
8ae1600
6bce7e0
d9b07cf
 
db710bd
578ad69
626626c
 
8729a3e
3cbe45e
db710bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e65f31d
 
 
7b09113
8729a3e
e0437fb
578ad69
e0437fb
578ad69
e0437fb
578ad69
 
 
 
 
 
 
e0437fb
578ad69
 
 
 
e0437fb
 
 
2de91c6
8729a3e
7b09113
8729a3e
 
 
 
 
83e5388
 
7b09113
8729a3e
 
9971ae0
8729a3e
 
 
 
 
 
 
 
 
 
 
59fe1f6
8729a3e
 
 
 
 
 
 
 
 
 
 
 
 
578ad69
 
 
 
 
 
8729a3e
 
 
 
312ec77
578ad69
312ec77
578ad69
 
 
 
 
8729a3e
def4405
 
578ad69
 
 
 
 
 
 
 
 
2de91c6
6bce7e0
578ad69
6bce7e0
 
7b09113
63fb484
7bd2a1d
63fb484
7bd2a1d
 
 
 
 
 
 
 
 
63fb484
8729a3e
e65f31d
d8e60e3
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
import gradio as gr
import pandas as pd
import os
import gradio as gr
from pathlib import Path
from huggingface_hub import login
from mutagen.mp3 import MP3
from mutagen.wave import WAVE
import json
from text_explanations import *
from utils import *
from load_and_save import *

persistent_storage = Path('/data')
password_files = os.getenv("password_files")

def state_to_number(*state_obj_list):

    list_numbers = []
    for state_obj in state_obj_list:
        number_obj = gr.Number(state_obj, visible = False)
        list_numbers.append(number_obj)
      
    return list_numbers


# ===================
# Gradio Interface
# ===================
with (gr.Blocks(theme=gr.themes.Soft(), css = css) as demo):
    # List of all audio files to annotate


    
    # Instructions for emotion annotation
    with gr.Sidebar(open = False) as sidebar:
        participant_id = gr.Textbox(label='What is your participant ID?', interactive = True)
        lets_go = gr.Button("Let's go!")
        cheat_sheet = gr.HTML(side_bar_html, padding = False)
        
    with gr.Tab("Instructions", elem_id = 'instructions'):
        instructions = gr.HTML(intro_html, padding = False)
        
        with gr.Blocks():
            description = gr.HTML(examples_explanation, padding = False)

            with gr.Accordion(label = "Neutral", open= False):
                neutral_audio = gr.Audio(value=f'{persistent_storage}/emotion_examples/neutral.wav', label = "Neutral")
            
            with gr.Accordion(label = "Happy",  open = False):
                happy_audio = gr.Audio(value=f'{persistent_storage}/emotion_examples/happy_low.wav', label = "Happy (Low Intensity)")
                happy_int_audio = gr.Audio(value=f'{persistent_storage}/emotion_examples/happy_intense.wav', label = "Happy (High Intensity)")
            
            with gr.Accordion(label = "Sad",  open = False):
                sad_audio = gr.Audio(value=f'{persistent_storage}/emotion_examples/sad_low.wav', label = "Sad (Low Intensity)")
                sad_int_audio = gr.Audio(value=f'{persistent_storage}/emotion_examples/sad_intense.wav', label = "Sad (High Intensity)")

            with gr.Accordion(label = "Anger",  open = False):
                angry_audio = gr.Audio(value=f'{persistent_storage}/emotion_examples/angry_low.wav', label = "Anger (Low Intensity)")
                angry_int_audio = gr.Audio(value=f'{persistent_storage}/emotion_examples/angry_intense.wav', label = "Anger (High Intensity)")

        instructions = gr.HTML(start_annotating, padding = False)
        image = gr.Image(label = "Annotation Interface", value = f"{persistent_storage}/instructions_annotation.png", container = False, type = "filepath", show_label = False, show_download_button = False, show_fullscreen_button = False,show_share_button = False)
        
    
    with gr.Tab("Annotation Interface"):
        ann_completed = gr.State(0)
        ann_completed_temp = gr.Number(0, visible = False)
        total = gr.State(0)
        total_temp = gr.Number(0, visible = False)
        current_index = gr.State(0)
        current_index_temp = gr.Number(0, visible = False)
        start = gr.State(0.0)
        start_temp = gr.Number(0, visible = False)
        end = gr.State(0.0)
        end_temp = gr.Number(0, visible = False)
        duration = gr.State(0.0)
        duration_temp = gr.Number(0, visible = False)
        n_clicks = gr.State(0)

        part_id = gr.State('')


        annotations = gr.State(pd.DataFrame())
        file_list = gr.State(pd.DataFrame())


        # Row with progress bar
        
        gr.HTML("""
        <div id="myProgress">
        <div id="myBar">
        <span id="progressText">Press "Let's go!" to start</span> 
        </div>
        </div>
        """, padding = False)
    
        # Row with audio player
        with gr.Row():
            audio_player = gr.Audio(value= 'blank.mp3', label="Audio", type="filepath", interactive=False, show_download_button = False, show_share_button = False, elem_id = "audio_to_annotate")

        # Hidden row with corresponding sentence
        with gr.Row():
            accordion = gr.Accordion(label="Click to see the sentence", open=False)
            with accordion:
                sentence_text = gr.Textbox(label="Transcription", interactive=False, value = 'This is a sentence.')
        # Row for emotion annotation and confidence
        with gr.Row():        
            emotions = gr.Radio(["Blank", "Joy", "Sad", "Angry", "Neutral"], label="Predominant Emotion", value = "Blank", visible = False)

        with gr.Row():    
            confidence = gr.Radio(["Blank","Very Uncertain", "Somewhat Uncertain", "Neutral", "Somewhat confident", "Very confident"], label="How confident are you that the annotated emotion is present in the recording?", visible = False)

        with gr.Row():
            # Comment section
            comments = gr.Textbox(label="Comments", visible =False)
            
        # Next and Previous Buttons
        with gr.Row():
            previous_button = gr.Button("Previous Example", visible = False)
            next_button = gr.Button("Next Example", visible = False)

        # Go back
        previous_button.click(
            previous_example,
            inputs=[annotations, file_list, emotions, confidence, comments, n_clicks, participant_id,  ann_completed , current_index],
            outputs=[annotations, sentence_text, audio_player, emotions, confidence, comments, n_clicks, start, end, duration, 
            ann_completed, current_index],).then(state_to_number, [start, end, duration, current_index, ann_completed, total], 
            [start_temp, end_temp, duration_temp, current_index_temp, ann_completed_temp, total_temp]).then(None, [], 
            [start_temp, end_temp, duration_temp, current_index_temp, 
            ann_completed_temp, total_temp], js = js_progress_bar)

        # Go to the next example
        next_button.click(
            next_example,
            inputs=[annotations, file_list,emotions, confidence, comments, n_clicks, participant_id, start, end, duration, ann_completed, current_index],
            outputs=[annotations,sentence_text, audio_player, emotions, confidence, comments, n_clicks, start, end, duration, ann_completed, 
            current_index],).then(state_to_number, [start, end, duration, current_index, ann_completed, total], 
            [start_temp, end_temp, duration_temp, current_index_temp, ann_completed_temp, total_temp]).then(None, [], 
            [start_temp, end_temp, duration_temp, current_index_temp, 
            ann_completed_temp, total_temp], js = js_progress_bar)
            
      
        
        buttons = [previous_button, next_button]
        data = [sentence_text, audio_player, emotions, confidence, comments]
        
        lets_go.click(deactivate_participant_id, [annotations, file_list,  total, participant_id, 
        lets_go, *buttons, *data, n_clicks, ann_completed, current_index], 
        [annotations, file_list, participant_id, part_id, lets_go, total, *buttons, 
        *data, n_clicks, start, end, duration, ann_completed, current_index]).then(state_to_number, [start, end, duration, current_index, ann_completed, total], 
        [start_temp, end_temp, duration_temp, current_index_temp, ann_completed_temp, total_temp]).then(None, [], 
        [start_temp, end_temp, duration_temp, current_index_temp, 
        ann_completed_temp, total_temp], js = js_progress_bar)

        audio_player.play(count_clicks, [n_clicks], [n_clicks])

        sidebar.collapse(None, [], [start, end, duration, current_index, ann_completed, total], js = js_progress_bar)
        sidebar.expand(None, [], [start, end, duration, current_index,ann_completed, total], js = js_progress_bar)
        
    
    with gr.Tab("Access Files"):

        with gr.Row():
            password = gr.Textbox(label="Enter Password", type="password")
            get_files_button = gr.Button("Get Files")
        
        with gr.Column():
            files = gr.File(label="Download Files", file_count="multiple", interactive=True)
            storage = gr.Text(label="Total Usage")
        
        get_files_button.click(fn=get_storage, inputs=[password], outputs=[files, storage])


        
demo.launch(allowed_paths = ['/data'])