File size: 6,018 Bytes
e698260
 
96f6a7b
bef4887
 
cd05049
e698260
 
 
 
 
 
 
 
 
 
 
 
 
 
96f6a7b
bef4887
 
 
e698260
 
fb7a690
 
5182145
05317bb
fb7a690
05317bb
e698260
 
 
 
 
4198c04
e698260
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4198c04
e698260
 
 
 
 
 
 
 
96f6a7b
bef4887
 
 
 
 
a497221
96f6a7b
bef4887
 
 
96f6a7b
5182145
 
 
 
 
 
 
 
 
 
a497221
5182145
 
 
 
 
 
 
 
 
e698260
 
 
 
 
 
 
 
 
 
 
 
 
bef4887
 
 
 
e698260
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bef4887
 
e698260
 
 
 
 
 
 
 
 
 
bef4887
 
 
 
e698260
 
 
 
 
5182145
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
from lang_ui import get_ui_lang
import gradio as gr
import file_name
import ffmpeg
import gdown
import time

# Display available langauges and set default UI language
ui_lang_index = 1
available_ui_lang = ["English", "Bahasa Indonesia"]
ui_lang = get_ui_lang(ui_lang_index)

lang_radio_choice = 1
model_dropdown_choice = 2

# Transcribe components
ui_lang_radio = gr.Radio(
    available_ui_lang, type="index", value=available_ui_lang[ui_lang_index], interactive=True, show_label=False)
top_markdown = gr.Markdown(
    ui_lang["top_markdown"])
input_url = gr.Textbox(
    max_lines=1, label=ui_lang["input_url_label"], info=ui_lang["input_url_info"], interactive=True)
url_download_button = gr.Button(
    ui_lang["download_button_value"], size='sm', interactive=True)
input_video = gr.Video(
    label=ui_lang["input_video_label"], interactive=True)
# input_video_button = gr.Button(
#     ui_lang["input_video_button_value"], interactive=True)
start_time = gr.Textbox("00:00:00", max_lines=1, placeholder="00:00:00",
                        label=ui_lang["start_time_label"], interactive=True)
end_time = gr.Textbox("00:00:00", max_lines=1, placeholder="99:99:99",
                      label=ui_lang["end_time_label"], interactive=True)
lang_radio = gr.Radio(
    ui_lang["lang_radio_choices"], label=ui_lang["lang_radio_label"], info=ui_lang["lang_radio_info"], type='index', interactive=True)
model_dropdown = gr.Dropdown(
    ui_lang["model_dropdown_choices"], label=ui_lang["model_dropdown_label"], info=ui_lang["model_dropdown_info"], type='index', interactive=True)
summary_checkbox = gr.Checkbox(
    label=ui_lang["summary_checkbox_label"], info=ui_lang["summary_checkbox_info"], interactive=False)
start_button = gr.Button(
    ui_lang["start_button_value"], variant="primary", interactive=True)

# Adjust components
middle_markdown = gr.Markdown(
    ui_lang["middle_markdown"])
adjust_audio = gr.Audio(interactive=False)
adjust_speaker = gr.Textbox(
    label=ui_lang["adjust_speaker_value"], interactive=False)
prev_button = gr.Button(ui_lang["prev_button_value"], interactive=False)
next_button = gr.Button(ui_lang["next_button_value"], interactive=False)
adjust_button = gr.Button(
    ui_lang["adjust_button_value"], variant="primary", interactive=False)

# Result components
bottom_markdown = gr.Markdown(
    ui_lang["bottom_markdown"]
)
output_video = gr.Video(label=ui_lang["output_video_label"], interactive=False)
output_file = gr.File(file_count="multiple", interactive=False)
output_transcribe = gr.Textbox(
    label=ui_lang["output_transcribe_label"], interactive=False, show_copy_button=True)
output_summary = gr.Textbox(
    interactive=False, show_copy_button=True)


def time_str(t):
    return '{0:02d}:{1:02d}:{2:02d}'.format(round(t // 3600),
                                            round(t % 3600 // 60),
                                            round(t % 60))


def get_video_from_url(url):
    gr.Info(ui_lang["get_video_start_info"])
    download_result = gdown.download(
        url, file_name.download_file, quiet=False, fuzzy=True)

    if (download_result is None):
        raise gr.Error(ui_lang["get_video_fail_info"])

    gr.Info(ui_lang["get_video_finished_info"])
    return file_name.download_file


# def clear_duration():
#     return [
#         start_time.update(None, interactive=False),
#         end_time.update(None, interactive=False)
#     ]


# def get_duration(input_file):
#     print("Checking file")
#     if input_file is None:
#         raise gr.Error(ui_lang["input_video_warning"])
#     print("Getting duration & Waiting")
#     info_json = ffmpeg.probe(input_file)
#     print("Probing finished")
#     duration_seconds = float(info_json['format']['duration'])
#     duration_formatted = time_str(duration_seconds)
#     return [
#         start_time.update("00:00:00", interactive=True),
#         end_time.update(duration_formatted, interactive=True)
#     ]


# Change language function


def change_lang(input):
    global ui_lang
    ui_lang = get_ui_lang(input)
    print(f"Change language to {available_ui_lang[input]}")
    return [
        # Top
        top_markdown.update(
            ui_lang["top_markdown"]),
        input_url.update(
            label=ui_lang["input_url_label"], info=ui_lang["input_url_info"]),
        url_download_button.update(
            ui_lang["download_button_value"]),
        input_video.update(
            label=ui_lang["input_video_label"]),
        start_time.update(
            label=ui_lang["start_time_label"]),
        end_time.update(
            label=ui_lang["end_time_label"]),
        lang_radio.update(
            choices=ui_lang["lang_radio_choices"], value=None, label=ui_lang["lang_radio_label"], info=ui_lang["lang_radio_info"],),
        model_dropdown.update(
            choices=ui_lang["model_dropdown_choices"], value=None, label=ui_lang["model_dropdown_label"], info=ui_lang["model_dropdown_info"]),
        start_button.update(
            ui_lang["start_button_value"]),

        # Middle
        middle_markdown.update(
            ui_lang["middle_markdown"]),
        adjust_speaker.update(
            label=ui_lang["adjust_speaker_value"]),
        prev_button.update(
            ui_lang["prev_button_value"]),
        next_button.update(
            ui_lang["next_button_value"]),
        adjust_button.update(
            ui_lang["adjust_button_value"]),

        # Bottom
        bottom_markdown.update(
            ui_lang["bottom_markdown"]),
        output_video.update(
            label=ui_lang["output_video_label"]),
        output_transcribe.update(
            label=ui_lang["output_transcribe_label"]),
    ]


# comp_to_update and change_lang return must always be in equal number
comp_to_update = [
    top_markdown, input_url, url_download_button, input_video, start_time, end_time, lang_radio, model_dropdown, start_button, middle_markdown, adjust_speaker, prev_button, next_button, adjust_button, bottom_markdown, output_video, output_transcribe]