File size: 7,058 Bytes
1bf4da3
 
 
 
 
 
 
 
13aeb09
1bf4da3
 
aa6222e
52d84c5
1bf4da3
aa6222e
 
13aeb09
aa6222e
13aeb09
 
52d84c5
f612514
aa6222e
13aeb09
f612514
1bf4da3
 
f612514
 
 
 
 
 
 
 
 
 
13aeb09
f612514
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe19555
 
 
 
 
 
 
 
f612514
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe19555
 
 
 
 
 
 
 
13aeb09
 
 
 
fe19555
 
 
 
 
98c66ee
 
 
13aeb09
1bf4da3
13aeb09
 
 
 
 
 
d6b712b
 
 
98c66ee
13aeb09
1bf4da3
52d84c5
 
 
 
 
 
 
 
 
 
 
 
 
 
f612514
 
 
 
52d84c5
 
 
 
 
 
 
 
 
f612514
 
 
 
 
 
 
 
 
 
fe19555
 
 
 
 
f612514
1bf4da3
aa6222e
 
 
 
 
1bf4da3
 
 
 
 
 
 
 
 
 
 
 
aa6222e
f612514
 
 
13aeb09
fe19555
13aeb09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52d84c5
 
 
f612514
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1bf4da3
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
"""
File: languages.py
Author: Elena Ryumina and Dmitry Ryumin
Description: Selected language event handlers for Gradio app.
License: MIT License
"""

import gradio as gr
from pathlib import Path

# Importing necessary components for the Gradio app
from app.description import DESCRIPTIONS
from app.description_steps import STEP_1, STEP_2
from app.config import config_data
from app.components import (
    files_create_ui,
    video_create_ui,
    dropdown_create_ui,
    button,
    html_message,
    dataframe,
    radio_create_ui,
)
from app.utils import get_language_settings
from app.practical_tasks import supported_practical_tasks


def event_handler_languages(
    languages,
    files,
    video,
    type_modes,
    pt_scores,
    csv_pt_scores,
    practical_tasks,
    practical_subtasks,
):
    lang_id, choices = get_language_settings(languages)
    lang_id_inverse = {0: 1, 1: 0}.get(lang_id, None)

    if type_modes == config_data.Settings_TYPE_MODES[0]:
        files_ui = files_create_ui(
            label="{} ({})".format(
                config_data.OtherMessages_VIDEO_FILES[
                    config_data.AppSettings_DEFAULT_LANG_ID
                ],
                ", ".join(config_data.Settings_SUPPORTED_VIDEO_EXT),
            ),
            file_types=[f".{ext}" for ext in config_data.Settings_SUPPORTED_VIDEO_EXT],
        )
        webcam = gr.Video(interactive=False, visible=False)
        switching_modes = button(
            config_data.OtherMessages_SWITCHEHG_MODES_ONLINE[lang_id],
            True,
            1,
            "./images/webcam.ico",
            True,
            "switching_modes",
        )
        examples = button(
            config_data.OtherMessages_EXAMPLES_APP[lang_id],
            True,
            1,
            "./images/examples.ico",
            True,
            "examples_oceanai",
        )
    elif type_modes == config_data.Settings_TYPE_MODES[1]:
        files_ui = files_create_ui(
            label="{} ({})".format(
                config_data.OtherMessages_VIDEO_FILES[lang_id],
                ", ".join(config_data.Settings_SUPPORTED_VIDEO_EXT),
            ),
            file_types=[f".{ext}" for ext in config_data.Settings_SUPPORTED_VIDEO_EXT],
            interactive=False,
            visible=False,
        )
        webcam = gr.Video(interactive=True, visible=True)
        switching_modes = button(
            config_data.OtherMessages_SWITCHEHG_MODES_OFFLINE[lang_id],
            True,
            1,
            "./images/videos.ico",
            True,
            "switching_modes",
        )
        examples = button(
            config_data.OtherMessages_EXAMPLE_APP[lang_id],
            True,
            1,
            "./images/examples.ico",
            True,
            "examples_oceanai",
        )

    if not video:
        video = video_create_ui(label=config_data.OtherMessages_VIDEO_PLAYER[lang_id])
        noti_videos = html_message(
            (
                config_data.InformationMessages_NOTI_VIDEOS[lang_id].split("(")[0]
                if lang_id == 0
                else config_data.InformationMessages_NOTI_VIDEOS[lang_id]
            ),
            False,
            True,
            "notifications",
        )
    else:
        video = video_create_ui(
            value=video,
            label=config_data.OtherMessages_VIDEO_PLAYER[lang_id],
            file_name=Path(video).name,
        )
        noti_videos = html_message(
            config_data.OtherMessages_NOTI_CALCULATE[lang_id],
            True,
            False if pt_scores.shape[1] >= 7 else True,
            "notifications",
        )

    csv_pt_scores = files_create_ui(
        csv_pt_scores if pt_scores.shape[1] >= 7 else None,
        "single",
        [".csv"],
        config_data.OtherMessages_EXPORT_PT_SCORES[lang_id],
        True,
        False,
        True if pt_scores.shape[1] >= 7 else False,
        "csv-container",
    )
    step_2 = gr.HTML(
        value=STEP_2[lang_id], visible=True if pt_scores.shape[1] >= 7 else False
    )

    practical_tasks_column = gr.Column(
        visible=True if pt_scores.shape[1] >= 7 else False
    )

    if pt_scores.shape[1] >= 7:
        pt_scores = dataframe(
            headers=(config_data.Dataframes_PT_SCORES[lang_id]),
            values=pt_scores.values.tolist(),
            visible=True,
        )
    else:
        pt_scores = dataframe(visible=False)

    current_lang_tasks = list(map(str, supported_practical_tasks[lang_id].keys()))
    inverse_lang_tasks = list(
        map(str, supported_practical_tasks[lang_id_inverse].keys())
    )

    if practical_tasks in inverse_lang_tasks:
        practical_task = current_lang_tasks[inverse_lang_tasks.index(practical_tasks)]
    else:
        practical_task = next(iter(supported_practical_tasks[lang_id]))

    # print(current_lang_tasks, "\n")
    # print(inverse_lang_tasks, "\n")
    # print(practical_tasks, "\n")
    # print(supported_practical_tasks, "\n")
    # print(practical_subtasks, "\n")

    return (
        gr.Markdown(value=DESCRIPTIONS[lang_id]),
        gr.HTML(value=STEP_1[lang_id]),
        gr.Image(
            value=config_data.StaticPaths_IMAGES + config_data.Images_LANGUAGES[lang_id]
        ),
        dropdown_create_ui(
            label=None,
            info=None,
            choices=choices,
            value=choices[lang_id],
            visible=True,
            show_label=False,
            elem_classes="dropdown-language-container",
        ),
        gr.Tab(config_data.Labels_APP_LABEL[lang_id]),
        gr.Tab(config_data.Labels_ABOUT_APP_LABEL[lang_id]),
        gr.Tab(config_data.Labels_ABOUT_AUTHORS_LABEL[lang_id]),
        gr.Tab(config_data.Labels_REQUIREMENTS_LABEL[lang_id]),
        files_ui,
        webcam,
        switching_modes,
        video,
        examples,
        button(
            config_data.OtherMessages_CALCULATE_PT_SCORES[lang_id],
            True if files else False,
            3,
            "./images/calculate_pt_scores.ico",
            True,
            "calculate_oceanai",
        ),
        button(
            config_data.OtherMessages_CLEAR_APP[lang_id],
            True if files else False,
            1,
            "./images/clear.ico",
            True,
            "clear_oceanai",
        ),
        noti_videos,
        pt_scores,
        csv_pt_scores,
        step_2,
        practical_tasks_column,
        radio_create_ui(
            practical_task,
            config_data.Labels_PRACTICAL_TASKS_LABEL[lang_id],
            current_lang_tasks,
            config_data.InformationMessages_PRACTICAL_TASKS_INFO[lang_id],
            True,
            True,
        ),
        radio_create_ui(
            supported_practical_tasks[lang_id][practical_task][0],
            config_data.Labels_PRACTICAL_SUBTASKS_LABEL[lang_id],
            supported_practical_tasks[lang_id][practical_task],
            config_data.InformationMessages_PRACTICAL_SUBTASKS_INFO[lang_id],
            True,
            True,
        ),
    )