File size: 6,000 Bytes
42c4f80
 
 
 
 
 
 
78f883e
f612514
78f883e
 
42c4f80
f612514
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42c4f80
78f883e
fe19555
f612514
78f883e
f612514
42c4f80
78f883e
 
 
 
 
f612514
fe19555
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f612514
 
98c66ee
fe19555
 
98c66ee
 
 
f612514
 
 
 
 
 
 
 
fe19555
f612514
 
 
 
 
 
 
fe19555
f612514
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
File: examples_blocks.py
Author: Elena Ryumina and Dmitry Ryumin
Description: Event handler for the addition of examples to the Gradio app.
License: MIT License
"""

import re
import gradio as gr
from pathlib import Path

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


def event_handler_examples_blocks(language, type_modes):
    lang_id, _ = get_language_settings(language)

    first_practical_task = next(iter(supported_practical_tasks[lang_id]))

    videos_dir = Path("videos")
    video_files = sorted(
        (str(p) for p in videos_dir.glob("*.mp4")),
        key=lambda x: int(re.search(r"\d+", Path(x).stem).group()),
    )

    if type_modes == config_data.Settings_TYPE_MODES[0]:
        files_ui = files_create_ui(
            value=video_files,
            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],
        )
    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,
        )

    return (
        html_message(
            config_data.OtherMessages_NOTI_CALCULATE[lang_id],
            True,
            True,
            "notifications",
        ),
        files_ui,
        video_create_ui(
            value=video_files[0],
            label=config_data.OtherMessages_VIDEO_PLAYER[lang_id],
            file_name=Path(Path(video_files[0]).name).name,
        ),
        button(
            config_data.OtherMessages_CALCULATE_PT_SCORES[lang_id],
            True,
            3,
            "./images/calculate_pt_scores.ico",
            True,
            "calculate_oceanai",
        ),
        button(
            config_data.OtherMessages_CLEAR_APP[lang_id],
            True,
            1,
            "./images/clear.ico",
            True,
            "clear_oceanai",
        ),
        dataframe(visible=False),
        files_create_ui(
            None,
            "single",
            [".csv"],
            config_data.OtherMessages_EXPORT_PT_SCORES[lang_id],
            True,
            False,
            False,
            "csv-container",
        ),
        gr.HTML(value=STEP_2[lang_id], visible=False),
        gr.Column(visible=False),
        radio_create_ui(
            first_practical_task,
            config_data.Labels_PRACTICAL_TASKS_LABEL[lang_id],
            list(map(str, supported_practical_tasks[lang_id].keys())),
            config_data.InformationMessages_PRACTICAL_TASKS_INFO[lang_id],
            True,
            True,
        ),
        radio_create_ui(
            supported_practical_tasks[lang_id][first_practical_task][0],
            config_data.Labels_PRACTICAL_SUBTASKS_LABEL[lang_id],
            supported_practical_tasks[lang_id][first_practical_task],
            config_data.InformationMessages_PRACTICAL_SUBTASKS_INFO[lang_id],
            True,
            True,
        ),
        gr.JSON(
            value={
                str(task): supported_practical_tasks[index].get(task, [None])[0]
                for index in range(len(supported_practical_tasks))
                for task in supported_practical_tasks[index].keys()
            },
            visible=False,
            render=True,
        ),
        gr.Column(visible=False),
        dropdown_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        dropdown_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        dropdown_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        number_create_ui(visible=False),
        gr.Row(visible=False),
        gr.Column(visible=False),
        dataframe(visible=False),
        files_create_ui(
            None,
            "single",
            [".csv"],
            config_data.OtherMessages_EXPORT_PS,
            True,
            False,
            False,
            "csv-container",
        ),
        gr.Accordion(visible=False),
        gr.HTML(visible=False),
        dataframe(visible=False),
        gr.Column(visible=False),
        video_create_ui(visible=False),
        gr.Column(visible=False),
        gr.Row(visible=False),
        gr.Row(visible=False),
        gr.Image(visible=False),
        textbox_create_ui(visible=False),
        gr.Row(visible=False),
        gr.Image(visible=False),
        textbox_create_ui(visible=False),
        gr.Row(visible=False),
        gr.Row(visible=False),
        gr.Image(visible=False),
        textbox_create_ui(visible=False),
        gr.Row(visible=False),
        gr.Image(visible=False),
        textbox_create_ui(visible=False),
        html_message(config_data.InformationMessages_NOTI_IN_DEV, False, False),
    )