Spaces:
Sleeping
Sleeping
Commit
·
2d7377d
1
Parent(s):
c591102
add Ukrainian localization
Browse files- Functions/caption_editor_functions.py +3 -2
- Resources/localization.py +85 -0
- app.py +24 -23
Functions/caption_editor_functions.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
from Functions.db_connection import default_app
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
def save_captions_to_db(df, video_id, user):
|
|
@@ -9,9 +10,9 @@ def save_captions_to_db(df, video_id, user):
|
|
| 9 |
df_json = data.to_dict(orient="index")
|
| 10 |
default_app.database().child("video_captions").child(video_id).child("captions").set(df_json)
|
| 11 |
default_app.database().child("video_captions").child(video_id).child("username").set(user)
|
| 12 |
-
return "
|
| 13 |
except Exception as e:
|
| 14 |
-
return f"
|
| 15 |
|
| 16 |
|
| 17 |
def request_captions_by_video_id(video_id):
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
from Functions.db_connection import default_app
|
| 3 |
+
from Resources.localization import get_string
|
| 4 |
|
| 5 |
|
| 6 |
def save_captions_to_db(df, video_id, user):
|
|
|
|
| 10 |
df_json = data.to_dict(orient="index")
|
| 11 |
default_app.database().child("video_captions").child(video_id).child("captions").set(df_json)
|
| 12 |
default_app.database().child("video_captions").child(video_id).child("username").set(user)
|
| 13 |
+
return get_string("save_successful")
|
| 14 |
except Exception as e:
|
| 15 |
+
return f"{get_string('save_failed')} {str(e)}"
|
| 16 |
|
| 17 |
|
| 18 |
def request_captions_by_video_id(video_id):
|
Resources/localization.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Localization strings for the Caption Editor app
|
| 2 |
+
|
| 3 |
+
# Set the active language here: "en" or "uk"
|
| 4 |
+
LANGUAGE = "uk"
|
| 5 |
+
|
| 6 |
+
STRINGS = {
|
| 7 |
+
"en": {
|
| 8 |
+
# Header and login
|
| 9 |
+
"app_title": "Caption Editor",
|
| 10 |
+
"please_log_in": "Please log in via Hugging Face",
|
| 11 |
+
"logged_in_as": "Logged in as",
|
| 12 |
+
"log_in_button": "Log in",
|
| 13 |
+
|
| 14 |
+
# Main interface
|
| 15 |
+
"next_button": "Finish this video and go to next",
|
| 16 |
+
"add_entry_button": "Add Entry",
|
| 17 |
+
|
| 18 |
+
# Table headers
|
| 19 |
+
"header_start": "Start",
|
| 20 |
+
"header_text": "Text",
|
| 21 |
+
"header_end": "End",
|
| 22 |
+
|
| 23 |
+
# Edit form
|
| 24 |
+
"edit_caption_title": "Edit Caption Entry",
|
| 25 |
+
"start_time_label": "Start Time (seconds)",
|
| 26 |
+
"caption_text_label": "Caption Text",
|
| 27 |
+
"caption_text_placeholder": "Enter caption text...",
|
| 28 |
+
"end_time_label": "End Time (seconds)",
|
| 29 |
+
"insert_current_time": "Insert Video Current Time",
|
| 30 |
+
"save_entry_button": "Save Entry",
|
| 31 |
+
"update_entry_button": "Update Entry",
|
| 32 |
+
"add_entry_button_form": "Add Entry",
|
| 33 |
+
"cancel_button": "Cancel",
|
| 34 |
+
|
| 35 |
+
# Messages
|
| 36 |
+
"please_sign_in": "Please sign in to save changes",
|
| 37 |
+
"start_less_than_end": "Start time must be less than end time",
|
| 38 |
+
"text_cannot_be_empty": "Text cannot be empty",
|
| 39 |
+
"save_successful": "Save successful!",
|
| 40 |
+
"save_failed": "Save failed:",
|
| 41 |
+
"invalid_time_format": "Invalid time format:",
|
| 42 |
+
"error": "Error:",
|
| 43 |
+
},
|
| 44 |
+
"uk": {
|
| 45 |
+
# Header and login
|
| 46 |
+
"app_title": "Редактор субтитрів",
|
| 47 |
+
"please_log_in": "Будь ласка, увійдіть через Hugging Face",
|
| 48 |
+
"logged_in_as": "Ви увійшли як",
|
| 49 |
+
"log_in_button": "Увійти",
|
| 50 |
+
|
| 51 |
+
# Main interface
|
| 52 |
+
"next_button": "Завершити відео і перейти до наступного",
|
| 53 |
+
"add_entry_button": "Додати субтитр",
|
| 54 |
+
|
| 55 |
+
# Table headers
|
| 56 |
+
"header_start": "Початок",
|
| 57 |
+
"header_text": "Текст",
|
| 58 |
+
"header_end": "Кінець",
|
| 59 |
+
|
| 60 |
+
# Edit form
|
| 61 |
+
"edit_caption_title": "Редагувати субтитр",
|
| 62 |
+
"start_time_label": "Час початку (секунди)",
|
| 63 |
+
"caption_text_label": "Текст субтитру",
|
| 64 |
+
"caption_text_placeholder": "Введіть текст субтитру...",
|
| 65 |
+
"end_time_label": "Час кінця (секунди)",
|
| 66 |
+
"insert_current_time": "Вставити поточний час відео",
|
| 67 |
+
"save_entry_button": "Зберегти запис",
|
| 68 |
+
"update_entry_button": "Оновити запис",
|
| 69 |
+
"add_entry_button_form": "Додати запис",
|
| 70 |
+
"cancel_button": "Скасувати",
|
| 71 |
+
|
| 72 |
+
# Messages
|
| 73 |
+
"please_sign_in": "Будь ласка, увійдіть, щоб зберегти зміни",
|
| 74 |
+
"start_less_than_end": "Час початку повинен бути менше часу кінця",
|
| 75 |
+
"text_cannot_be_empty": "Текст не може бути порожнім",
|
| 76 |
+
"save_successful": "Успішно збережено!",
|
| 77 |
+
"save_failed": "Помилка збереження:",
|
| 78 |
+
"invalid_time_format": "Невірний формат часу:",
|
| 79 |
+
"error": "Помилка:",
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
def get_string(key):
|
| 84 |
+
"""Get localized string by key"""
|
| 85 |
+
return STRINGS[LANGUAGE].get(key, key)
|
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from Functions.video_player_functions import youtube_link_to_id, get_video_link_
|
|
| 4 |
from Functions.caption_editor_functions import request_captions_by_video_id, save_captions_to_db
|
| 5 |
from Resources.css import css
|
| 6 |
from Resources.js import yt_init_js
|
|
|
|
| 7 |
|
| 8 |
next_video_pointer = 0
|
| 9 |
user = "anonymous_user"
|
|
@@ -30,9 +31,9 @@ def on_row_select(df, evt: gr.SelectData):
|
|
| 30 |
gr.update(value=str(row['Text'])), # text_input
|
| 31 |
gr.update(value=float(row['End'])), # end_time
|
| 32 |
gr.update(value=row_idx), # selected_row_idx
|
| 33 |
-
gr.update(value="
|
| 34 |
)
|
| 35 |
-
return gr.update(visible=False), "", "", "", -1, "
|
| 36 |
|
| 37 |
|
| 38 |
def show_add_entry_form():
|
|
@@ -43,23 +44,23 @@ def show_add_entry_form():
|
|
| 43 |
gr.update(value=""), # text_input
|
| 44 |
gr.update(value=0.0), # end_time
|
| 45 |
gr.update(value=-1), # selected_row_idx (-1 means new entry)
|
| 46 |
-
gr.update(value="
|
| 47 |
)
|
| 48 |
|
| 49 |
|
| 50 |
def save_entry(df, start_time, text, end_time, selected_row_idx, video_id):
|
| 51 |
"""Save or update a caption entry"""
|
| 52 |
if user == "anonymous_user":
|
| 53 |
-
return df, gr.update(visible=True), gr.Warning("
|
| 54 |
try:
|
| 55 |
start_time = float(start_time)
|
| 56 |
end_time = float(end_time)
|
| 57 |
|
| 58 |
if start_time >= end_time:
|
| 59 |
-
return df, gr.update(visible=True), gr.Warning("
|
| 60 |
|
| 61 |
if not text.strip():
|
| 62 |
-
return df, gr.update(visible=True), gr.Warning("
|
| 63 |
|
| 64 |
df_copy = df.copy()
|
| 65 |
|
|
@@ -88,9 +89,9 @@ def save_entry(df, start_time, text, end_time, selected_row_idx, video_id):
|
|
| 88 |
)
|
| 89 |
|
| 90 |
except ValueError as e:
|
| 91 |
-
return df, gr.update(visible=True), gr.Warning(f"
|
| 92 |
except Exception as e:
|
| 93 |
-
return df, gr.update(visible=True), gr.Error(f"
|
| 94 |
|
| 95 |
|
| 96 |
def cancel_edit():
|
|
@@ -128,21 +129,21 @@ with gr.Blocks(css=css, head=yt_init_js, fill_width=True) as main_page:
|
|
| 128 |
|
| 129 |
with gr.Row(variant="panel"):
|
| 130 |
with gr.Column(scale=4):
|
| 131 |
-
gr.Markdown("##
|
| 132 |
with gr.Column(scale=4):
|
| 133 |
@gr.render(inputs=user_state)
|
| 134 |
def check_login(logged_in_user):
|
| 135 |
if logged_in_user == "anonymous_user":
|
| 136 |
-
gr.Markdown("
|
| 137 |
else:
|
| 138 |
-
gr.Markdown(f"
|
| 139 |
with gr.Column(scale=1, min_width=50):
|
| 140 |
-
gr.LoginButton(value="
|
| 141 |
|
| 142 |
with gr.Row():
|
| 143 |
with gr.Column(scale=2, min_width=600):
|
| 144 |
video_embed = gr.HTML(value=get_youtube_player_html())
|
| 145 |
-
next_video_button = gr.Button("
|
| 146 |
with gr.Column(scale=1, min_width=200):
|
| 147 |
caption_editor = gr.DataFrame(
|
| 148 |
interactive=False,
|
|
@@ -150,27 +151,27 @@ with gr.Blocks(css=css, head=yt_init_js, fill_width=True) as main_page:
|
|
| 150 |
datatype=["number", "str", "number"],
|
| 151 |
col_count=(3, "fixed"),
|
| 152 |
column_widths=["20%", "60%", "20%"],
|
| 153 |
-
headers=["
|
| 154 |
wrap=True
|
| 155 |
)
|
| 156 |
-
add_entry_button = gr.Button("
|
| 157 |
|
| 158 |
with gr.Row():
|
| 159 |
with gr.Group(visible=False) as editing_panel:
|
| 160 |
-
gr.Markdown("###
|
| 161 |
with gr.Row(equal_height=False):
|
| 162 |
with gr.Column():
|
| 163 |
-
start_time_input = gr.Textbox(label="
|
| 164 |
-
insert_start_time_button = gr.Button("
|
| 165 |
with gr.Column():
|
| 166 |
-
text_input = gr.Textbox(label="
|
| 167 |
with gr.Column():
|
| 168 |
-
end_time_input = gr.Textbox(label="
|
| 169 |
-
insert_end_time_button = gr.Button("
|
| 170 |
|
| 171 |
with gr.Row(equal_height=False):
|
| 172 |
-
save_entry_button = gr.Button("
|
| 173 |
-
cancel_button = gr.Button("
|
| 174 |
|
| 175 |
save_result = gr.Markdown()
|
| 176 |
|
|
|
|
| 4 |
from Functions.caption_editor_functions import request_captions_by_video_id, save_captions_to_db
|
| 5 |
from Resources.css import css
|
| 6 |
from Resources.js import yt_init_js
|
| 7 |
+
from Resources.localization import get_string
|
| 8 |
|
| 9 |
next_video_pointer = 0
|
| 10 |
user = "anonymous_user"
|
|
|
|
| 31 |
gr.update(value=str(row['Text'])), # text_input
|
| 32 |
gr.update(value=float(row['End'])), # end_time
|
| 33 |
gr.update(value=row_idx), # selected_row_idx
|
| 34 |
+
gr.update(value=get_string("update_entry_button")) # save_entry_button
|
| 35 |
)
|
| 36 |
+
return gr.update(visible=False), "", "", "", -1, get_string("save_entry_button")
|
| 37 |
|
| 38 |
|
| 39 |
def show_add_entry_form():
|
|
|
|
| 44 |
gr.update(value=""), # text_input
|
| 45 |
gr.update(value=0.0), # end_time
|
| 46 |
gr.update(value=-1), # selected_row_idx (-1 means new entry)
|
| 47 |
+
gr.update(value=get_string("add_entry_button_form")) # save_entry_button
|
| 48 |
)
|
| 49 |
|
| 50 |
|
| 51 |
def save_entry(df, start_time, text, end_time, selected_row_idx, video_id):
|
| 52 |
"""Save or update a caption entry"""
|
| 53 |
if user == "anonymous_user":
|
| 54 |
+
return df, gr.update(visible=True), gr.Warning(get_string("please_sign_in"))
|
| 55 |
try:
|
| 56 |
start_time = float(start_time)
|
| 57 |
end_time = float(end_time)
|
| 58 |
|
| 59 |
if start_time >= end_time:
|
| 60 |
+
return df, gr.update(visible=True), gr.Warning(get_string("start_less_than_end"))
|
| 61 |
|
| 62 |
if not text.strip():
|
| 63 |
+
return df, gr.update(visible=True), gr.Warning(get_string("text_cannot_be_empty"))
|
| 64 |
|
| 65 |
df_copy = df.copy()
|
| 66 |
|
|
|
|
| 89 |
)
|
| 90 |
|
| 91 |
except ValueError as e:
|
| 92 |
+
return df, gr.update(visible=True), gr.Warning(f"{get_string('invalid_time_format')} {str(e)}")
|
| 93 |
except Exception as e:
|
| 94 |
+
return df, gr.update(visible=True), gr.Error(f"{get_string('error')} {str(e)}")
|
| 95 |
|
| 96 |
|
| 97 |
def cancel_edit():
|
|
|
|
| 129 |
|
| 130 |
with gr.Row(variant="panel"):
|
| 131 |
with gr.Column(scale=4):
|
| 132 |
+
gr.Markdown(f"## {get_string('app_title')}")
|
| 133 |
with gr.Column(scale=4):
|
| 134 |
@gr.render(inputs=user_state)
|
| 135 |
def check_login(logged_in_user):
|
| 136 |
if logged_in_user == "anonymous_user":
|
| 137 |
+
gr.Markdown(get_string("please_log_in"), rtl=True)
|
| 138 |
else:
|
| 139 |
+
gr.Markdown(f"{get_string('logged_in_as')} {logged_in_user.username}", rtl=True)
|
| 140 |
with gr.Column(scale=1, min_width=50):
|
| 141 |
+
gr.LoginButton(value=get_string("log_in_button"), logout_value=get_string("log_in_button"))
|
| 142 |
|
| 143 |
with gr.Row():
|
| 144 |
with gr.Column(scale=2, min_width=600):
|
| 145 |
video_embed = gr.HTML(value=get_youtube_player_html())
|
| 146 |
+
next_video_button = gr.Button(get_string("next_button"), key="next_video")
|
| 147 |
with gr.Column(scale=1, min_width=200):
|
| 148 |
caption_editor = gr.DataFrame(
|
| 149 |
interactive=False,
|
|
|
|
| 151 |
datatype=["number", "str", "number"],
|
| 152 |
col_count=(3, "fixed"),
|
| 153 |
column_widths=["20%", "60%", "20%"],
|
| 154 |
+
headers=[get_string("header_start"), get_string("header_text"), get_string("header_end")],
|
| 155 |
wrap=True
|
| 156 |
)
|
| 157 |
+
add_entry_button = gr.Button(get_string("add_entry_button"), variant="secondary")
|
| 158 |
|
| 159 |
with gr.Row():
|
| 160 |
with gr.Group(visible=False) as editing_panel:
|
| 161 |
+
gr.Markdown(f"### {get_string('edit_caption_title')}")
|
| 162 |
with gr.Row(equal_height=False):
|
| 163 |
with gr.Column():
|
| 164 |
+
start_time_input = gr.Textbox(label=get_string("start_time_label"), value="0.000", interactive=False)
|
| 165 |
+
insert_start_time_button = gr.Button(get_string("insert_current_time"))
|
| 166 |
with gr.Column():
|
| 167 |
+
text_input = gr.Textbox(label=get_string("caption_text_label"), placeholder=get_string("caption_text_placeholder"))
|
| 168 |
with gr.Column():
|
| 169 |
+
end_time_input = gr.Textbox(label=get_string("end_time_label"), value="0.000", interactive=False)
|
| 170 |
+
insert_end_time_button = gr.Button(get_string("insert_current_time"))
|
| 171 |
|
| 172 |
with gr.Row(equal_height=False):
|
| 173 |
+
save_entry_button = gr.Button(get_string("save_entry_button"), variant="primary")
|
| 174 |
+
cancel_button = gr.Button(get_string("cancel_button"), variant="secondary")
|
| 175 |
|
| 176 |
save_result = gr.Markdown()
|
| 177 |
|