Spaces:
Sleeping
Sleeping
Commit
·
5580bab
1
Parent(s):
7e5e159
Show complete videos option
Browse files- Functions/video_player_functions.py +2 -2
- Resources/localization.py +4 -2
- app.py +26 -21
Functions/video_player_functions.py
CHANGED
|
@@ -25,9 +25,9 @@ def get_video_embed_by_id(video_id):
|
|
| 25 |
return video_id
|
| 26 |
|
| 27 |
|
| 28 |
-
def get_video_link_by_pointer(pointer):
|
| 29 |
video = default_app.database().child("videos").child(str(pointer)).get().val()
|
| 30 |
-
if video["complete"]:
|
| 31 |
return None
|
| 32 |
return video["url"]
|
| 33 |
|
|
|
|
| 25 |
return video_id
|
| 26 |
|
| 27 |
|
| 28 |
+
def get_video_link_by_pointer(pointer, show_incomplete_only):
|
| 29 |
video = default_app.database().child("videos").child(str(pointer)).get().val()
|
| 30 |
+
if video["complete"] and show_incomplete_only:
|
| 31 |
return None
|
| 32 |
return video["url"]
|
| 33 |
|
Resources/localization.py
CHANGED
|
@@ -12,9 +12,10 @@ STRINGS = {
|
|
| 12 |
"log_in_button": "Log in",
|
| 13 |
|
| 14 |
# Main interface
|
| 15 |
-
"next_button": "
|
| 16 |
"add_entry_button": "Add Entry",
|
| 17 |
"editing_complete_checkbox": "Captions for this video are complete",
|
|
|
|
| 18 |
|
| 19 |
# Table headers
|
| 20 |
"header_start": "Start",
|
|
@@ -51,9 +52,10 @@ STRINGS = {
|
|
| 51 |
"log_in_button": "Увійти",
|
| 52 |
|
| 53 |
# Main interface
|
| 54 |
-
"next_button": "
|
| 55 |
"add_entry_button": "Додати субтитр",
|
| 56 |
"editing_complete_checkbox": "Розмітка цього відео готова",
|
|
|
|
| 57 |
|
| 58 |
# Table headers
|
| 59 |
"header_start": "Початок",
|
|
|
|
| 12 |
"log_in_button": "Log in",
|
| 13 |
|
| 14 |
# Main interface
|
| 15 |
+
"next_button": "Go to next video",
|
| 16 |
"add_entry_button": "Add Entry",
|
| 17 |
"editing_complete_checkbox": "Captions for this video are complete",
|
| 18 |
+
"show_incomplete_only_checkbox": "Only show videos with incomplete captions",
|
| 19 |
|
| 20 |
# Table headers
|
| 21 |
"header_start": "Start",
|
|
|
|
| 52 |
"log_in_button": "Увійти",
|
| 53 |
|
| 54 |
# Main interface
|
| 55 |
+
"next_button": "Перейти до наступного відео",
|
| 56 |
"add_entry_button": "Додати субтитр",
|
| 57 |
"editing_complete_checkbox": "Розмітка цього відео готова",
|
| 58 |
+
"show_incomplete_only_checkbox": "Показувати лише відео із незавершеною розміткою",
|
| 59 |
|
| 60 |
# Table headers
|
| 61 |
"header_start": "Початок",
|
app.py
CHANGED
|
@@ -108,31 +108,32 @@ def change_completion_status(completion_status):
|
|
| 108 |
change_video_completion_status(completion_status, (next_video_pointer + n_videos - 1) % n_videos)
|
| 109 |
|
| 110 |
|
| 111 |
-
def get_next_components():
|
| 112 |
global next_video_pointer
|
| 113 |
-
if
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
for i in range(n_videos + 1):
|
| 118 |
-
if next_video_link is not None:
|
| 119 |
-
break
|
| 120 |
-
next_video_link = get_video_link_by_pointer(next_video_pointer)
|
| 121 |
next_video_pointer = (next_video_pointer + 1) % n_videos
|
| 122 |
-
if next_video_link is None:
|
| 123 |
-
next_video_link = placeholder_link
|
| 124 |
-
next_video_pointer = -1
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
|
| 135 |
-
(start_captions, start_video_id) = get_next_components()
|
| 136 |
|
| 137 |
with gr.Blocks(css=css, head=yt_init_js, fill_width=True) as main_page:
|
| 138 |
user_state = gr.State("anonymous_user")
|
|
@@ -160,6 +161,9 @@ with gr.Blocks(css=css, head=yt_init_js, fill_width=True) as main_page:
|
|
| 160 |
with gr.Column(scale=2, min_width=600):
|
| 161 |
video_embed = gr.HTML(value=get_youtube_player_html())
|
| 162 |
next_video_button = gr.Button(get_string("next_button"), key="next_video")
|
|
|
|
|
|
|
|
|
|
| 163 |
with gr.Column(scale=1, min_width=200):
|
| 164 |
caption_editor = gr.DataFrame(
|
| 165 |
interactive=False,
|
|
@@ -207,6 +211,7 @@ with gr.Blocks(css=css, head=yt_init_js, fill_width=True) as main_page:
|
|
| 207 |
|
| 208 |
next_video_button.click(
|
| 209 |
fn=get_next_components,
|
|
|
|
| 210 |
outputs=[caption_editor, current_video_id]
|
| 211 |
)
|
| 212 |
next_video_button.click(
|
|
@@ -260,4 +265,4 @@ with gr.Blocks(css=css, head=yt_init_js, fill_width=True) as main_page:
|
|
| 260 |
|
| 261 |
cancel_button.click(fn=cancel_edit, outputs=[editing_panel])
|
| 262 |
|
| 263 |
-
main_page.launch(share=True)
|
|
|
|
| 108 |
change_video_completion_status(completion_status, (next_video_pointer + n_videos - 1) % n_videos)
|
| 109 |
|
| 110 |
|
| 111 |
+
def get_next_components(show_incomplete_only):
|
| 112 |
global next_video_pointer
|
| 113 |
+
if show_incomplete_only:
|
| 114 |
+
if next_video_pointer != -1:
|
| 115 |
+
next_video_link = get_video_link_by_pointer(next_video_pointer, show_incomplete_only)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
next_video_pointer = (next_video_pointer + 1) % n_videos
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
+
for i in range(n_videos + 1):
|
| 119 |
+
if next_video_link is not None:
|
| 120 |
+
break
|
| 121 |
+
next_video_link = get_video_link_by_pointer(next_video_pointer, show_incomplete_only)
|
| 122 |
+
next_video_pointer = (next_video_pointer + 1) % n_videos
|
| 123 |
+
if next_video_link is None:
|
| 124 |
+
next_video_link = placeholder_link
|
| 125 |
+
next_video_pointer = -1
|
| 126 |
+
|
| 127 |
+
try:
|
| 128 |
+
next_video_id = youtube_link_to_id(next_video_link)
|
| 129 |
+
next_captions = request_captions_by_video_id(next_video_id)
|
| 130 |
+
return next_captions, next_video_id
|
| 131 |
+
except (ValueError, Exception) as e:
|
| 132 |
+
empty_captions = pd.DataFrame(columns=["Start", "Text", "End"])
|
| 133 |
+
return empty_captions, "error"
|
| 134 |
|
| 135 |
|
| 136 |
+
(start_captions, start_video_id) = get_next_components(True)
|
| 137 |
|
| 138 |
with gr.Blocks(css=css, head=yt_init_js, fill_width=True) as main_page:
|
| 139 |
user_state = gr.State("anonymous_user")
|
|
|
|
| 161 |
with gr.Column(scale=2, min_width=600):
|
| 162 |
video_embed = gr.HTML(value=get_youtube_player_html())
|
| 163 |
next_video_button = gr.Button(get_string("next_button"), key="next_video")
|
| 164 |
+
show_incomplete_only_checkbox = gr.Checkbox(label=get_string("show_incomplete_only_checkbox"),
|
| 165 |
+
value=True)
|
| 166 |
+
|
| 167 |
with gr.Column(scale=1, min_width=200):
|
| 168 |
caption_editor = gr.DataFrame(
|
| 169 |
interactive=False,
|
|
|
|
| 211 |
|
| 212 |
next_video_button.click(
|
| 213 |
fn=get_next_components,
|
| 214 |
+
inputs=show_incomplete_only_checkbox,
|
| 215 |
outputs=[caption_editor, current_video_id]
|
| 216 |
)
|
| 217 |
next_video_button.click(
|
|
|
|
| 265 |
|
| 266 |
cancel_button.click(fn=cancel_edit, outputs=[editing_panel])
|
| 267 |
|
| 268 |
+
main_page.launch(share=True)
|