File size: 2,836 Bytes
f51c1fd
b322173
78f883e
b322173
f51c1fd
 
 
 
 
 
 
 
 
13aeb09
f51c1fd
 
d6b712b
13aeb09
 
f51c1fd
 
a26705a
 
 
 
 
 
13aeb09
f51c1fd
13aeb09
f51c1fd
 
24ee878
42c4f80
f51c1fd
 
42c4f80
13aeb09
24ee878
 
 
 
 
42c4f80
f51c1fd
 
13aeb09
 
 
f51c1fd
d6b712b
 
 
 
a26705a
d6b712b
13aeb09
 
 
 
 
f51c1fd
13aeb09
f51c1fd
 
24ee878
42c4f80
f51c1fd
 
24ee878
13aeb09
24ee878
 
 
 
 
 
f51c1fd
 
 
13aeb09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
File: files.py
Author: Elena Ryumina and Dmitry Ryumin
Description: Event handler for files.
License: MIT License
"""

import gradio as gr
from pathlib import Path

# Importing necessary components for the Gradio app
from app.config import config_data
from app.components import html_message, video_create_ui, button
from app.utils import get_language_settings


def event_handler_files(language, files, video, pt_scores):
    lang_id, _ = get_language_settings(language)

    if not files:
        return (
            html_message(
                config_data.InformationMessages_NOTI_VIDEOS[lang_id],
                False,
                True,
                "notifications",
            ),
            video_create_ui(label=config_data.OtherMessages_VIDEO_PLAYER[lang_id]),
            button(
                config_data.OtherMessages_CALCULATE_PT_SCORES[lang_id],
                False,
                3,
                "./images/calculate_pt_scores.ico",
                True,
                "calculate_oceanai",
            ),
            button(
                config_data.OtherMessages_CLEAR_APP[lang_id],
                False,
                1,
                "./images/clear.ico",
                True,
                "clear_oceanai",
            ),
        )

    if video not in files:
        video = files[0]

    return (
        html_message(
            config_data.OtherMessages_NOTI_CALCULATE[lang_id],
            True,
            False if pt_scores.shape[1] >= 7 else True,
            "notifications",
        ),
        video_create_ui(
            value=video,
            label=config_data.OtherMessages_VIDEO_PLAYER[lang_id],
            file_name=Path(Path(video).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",
        ),
    )


def event_handler_files_select(language, files, evt: gr.SelectData):
    lang_id, _ = get_language_settings(language)

    return video_create_ui(
        value=files[evt.index],
        label=config_data.OtherMessages_VIDEO_PLAYER[lang_id],
        file_name=evt.value,
    )


def event_handler_files_delete(language, files, video, evt: gr.DeletedFileData):
    global block_event_handler_files

    lang_id, _ = get_language_settings(language)

    if video == evt.file.path:
        video = files[0]

    return video_create_ui(
        value=video,
        label=config_data.OtherMessages_VIDEO_PLAYER[lang_id],
        file_name=Path(Path(video).name).name,
    )