Spaces:
Sleeping
Sleeping
Commit
·
f4f04e7
1
Parent(s):
c63553c
Render test 4
Browse files
app.py
CHANGED
|
@@ -133,113 +133,113 @@ with gr.Blocks() as main_page:
|
|
| 133 |
if logged_in_user is None:
|
| 134 |
gr.Markdown("## Please log in via Hugging Face")
|
| 135 |
else:
|
| 136 |
-
with gr.
|
| 137 |
-
with gr.
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
with
|
| 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 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
if (window.ytPlayer && window.ytPlayer.cueVideoById) {
|
| 188 |
-
|
| 189 |
window.ytPlayer.cueVideoById(videoId);
|
| 190 |
-
} else {
|
| 191 |
-
console.error('[Video Load] Player not ready yet');
|
| 192 |
}
|
| 193 |
-
}
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
# Handle row selection in DataFrame
|
| 197 |
-
caption_editor.select(
|
| 198 |
-
fn=on_row_select,
|
| 199 |
-
inputs=[caption_editor],
|
| 200 |
-
outputs=[editing_panel, start_time_input, text_input, end_time_input, selected_row_idx, save_entry_button]
|
| 201 |
-
)
|
| 202 |
-
|
| 203 |
-
# Handle add entry button
|
| 204 |
-
add_entry_button.click(
|
| 205 |
-
fn=show_add_entry_form,
|
| 206 |
-
outputs=[editing_panel, start_time_input, text_input, end_time_input, selected_row_idx, save_entry_button]
|
| 207 |
-
)
|
| 208 |
-
|
| 209 |
-
# Handle save entry
|
| 210 |
-
save_entry_button.click(
|
| 211 |
-
fn=save_entry,
|
| 212 |
-
inputs=[caption_editor, start_time_input, text_input, end_time_input,
|
| 213 |
-
selected_row_idx, current_video_id],
|
| 214 |
-
outputs=[caption_editor, editing_panel, save_result]
|
| 215 |
-
)
|
| 216 |
-
|
| 217 |
-
insert_start_time_button.click(fn=None, inputs=None, outputs=start_time_input,
|
| 218 |
-
js="() => window.ytPlayer ? +window.ytPlayer.getCurrentTime().toFixed(3) : 0")
|
| 219 |
-
|
| 220 |
-
insert_end_time_button.click(fn=None, inputs=None, outputs=end_time_input,
|
| 221 |
-
js="() => window.ytPlayer ? +window.ytPlayer.getCurrentTime().toFixed(3) : 0")
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
# Handle cancel
|
| 225 |
-
cancel_button.click(
|
| 226 |
-
fn=cancel_edit,
|
| 227 |
-
outputs=[editing_panel]
|
| 228 |
-
)
|
| 229 |
-
|
| 230 |
-
# Load initial video on page load
|
| 231 |
-
editor_page.load(
|
| 232 |
-
fn=None,
|
| 233 |
-
inputs=current_video_id,
|
| 234 |
-
outputs=None,
|
| 235 |
-
js="""(videoId) => {
|
| 236 |
-
const checkPlayer = setInterval(() => {
|
| 237 |
-
if (window.ytPlayer && window.ytPlayer.cueVideoById) {
|
| 238 |
-
clearInterval(checkPlayer);
|
| 239 |
-
window.ytPlayer.cueVideoById(videoId);
|
| 240 |
-
}
|
| 241 |
-
}, 100);
|
| 242 |
-
}"""
|
| 243 |
-
)
|
| 244 |
|
| 245 |
main_page.launch(share=True)
|
|
|
|
| 133 |
if logged_in_user is None:
|
| 134 |
gr.Markdown("## Please log in via Hugging Face")
|
| 135 |
else:
|
| 136 |
+
with gr.Row(key="row1"):
|
| 137 |
+
with gr.Column(scale=2, min_width=600, key="video_col"):
|
| 138 |
+
# Video player and "next video button
|
| 139 |
+
video_embed = gr.HTML(value=get_youtube_player_html(), key="video")
|
| 140 |
+
next_video_button = gr.Button("Next", key="next_video")
|
| 141 |
+
with gr.Column(scale=1, min_width=200, key="editor_col"):
|
| 142 |
+
# Read-only DataFrame with add button
|
| 143 |
+
caption_editor = gr.DataFrame(interactive=False,
|
| 144 |
+
elem_id="tbl",
|
| 145 |
+
value=start_captions,
|
| 146 |
+
datatype=["number", "str", "number"],
|
| 147 |
+
col_count=(3, "fixed"),
|
| 148 |
+
column_widths=["20%", "60%", "20%"],
|
| 149 |
+
headers=["Start", "Text", "End"],
|
| 150 |
+
wrap=True,
|
| 151 |
+
key="editor")
|
| 152 |
+
add_entry_button = gr.Button("Add Entry", variant="secondary", key="add_entry")
|
| 153 |
+
|
| 154 |
+
with gr.Row(key="row2"):
|
| 155 |
+
# Editing panel (initially hidden) - spans full width
|
| 156 |
+
with gr.Group(visible=False) as editing_panel:
|
| 157 |
+
gr.Markdown("### Edit Caption Entry")
|
| 158 |
+
with gr.Row(equal_height=False):
|
| 159 |
+
with gr.Column():
|
| 160 |
+
start_time_input = gr.Textbox(label="Start Time (seconds)", value="0.000", interactive=False)
|
| 161 |
+
insert_start_time_button = gr.Button("Insert Current Time")
|
| 162 |
+
with gr.Column():
|
| 163 |
+
text_input = gr.Textbox(label="Caption Text", placeholder="Enter caption text...")
|
| 164 |
+
|
| 165 |
+
with gr.Column():
|
| 166 |
+
end_time_input = gr.Textbox(label="End Time (seconds)", value="0.000", interactive=False)
|
| 167 |
+
insert_end_time_button = gr.Button("Insert Current Time")
|
| 168 |
+
|
| 169 |
+
with gr.Row(equal_height=False):
|
| 170 |
+
save_entry_button = gr.Button("Save Entry", variant="primary")
|
| 171 |
+
cancel_button = gr.Button("Cancel", variant="secondary")
|
| 172 |
+
|
| 173 |
+
save_result = gr.Markdown()
|
| 174 |
+
|
| 175 |
+
# Event handlers
|
| 176 |
+
next_video_button.click(
|
| 177 |
+
fn=get_next_components,
|
| 178 |
+
outputs=[caption_editor, current_video_id]
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
# Load video when current_video_id changes
|
| 182 |
+
current_video_id.change(
|
| 183 |
+
fn=None,
|
| 184 |
+
inputs=current_video_id,
|
| 185 |
+
outputs=None,
|
| 186 |
+
js="""(videoId) => {
|
| 187 |
+
if (window.ytPlayer && window.ytPlayer.cueVideoById) {
|
| 188 |
+
console.log('[Video Load] Calling cueVideoById with:', videoId);
|
| 189 |
+
window.ytPlayer.cueVideoById(videoId);
|
| 190 |
+
} else {
|
| 191 |
+
console.error('[Video Load] Player not ready yet');
|
| 192 |
+
}
|
| 193 |
+
}"""
|
| 194 |
+
)
|
| 195 |
+
|
| 196 |
+
# Handle row selection in DataFrame
|
| 197 |
+
caption_editor.select(
|
| 198 |
+
fn=on_row_select,
|
| 199 |
+
inputs=[caption_editor],
|
| 200 |
+
outputs=[editing_panel, start_time_input, text_input, end_time_input, selected_row_idx, save_entry_button]
|
| 201 |
+
)
|
| 202 |
+
|
| 203 |
+
# Handle add entry button
|
| 204 |
+
add_entry_button.click(
|
| 205 |
+
fn=show_add_entry_form,
|
| 206 |
+
outputs=[editing_panel, start_time_input, text_input, end_time_input, selected_row_idx, save_entry_button]
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
# Handle save entry
|
| 210 |
+
save_entry_button.click(
|
| 211 |
+
fn=save_entry,
|
| 212 |
+
inputs=[caption_editor, start_time_input, text_input, end_time_input,
|
| 213 |
+
selected_row_idx, current_video_id],
|
| 214 |
+
outputs=[caption_editor, editing_panel, save_result]
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
insert_start_time_button.click(fn=None, inputs=None, outputs=start_time_input,
|
| 218 |
+
js="() => window.ytPlayer ? +window.ytPlayer.getCurrentTime().toFixed(3) : 0")
|
| 219 |
+
|
| 220 |
+
insert_end_time_button.click(fn=None, inputs=None, outputs=end_time_input,
|
| 221 |
+
js="() => window.ytPlayer ? +window.ytPlayer.getCurrentTime().toFixed(3) : 0")
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
# Handle cancel
|
| 225 |
+
cancel_button.click(
|
| 226 |
+
fn=cancel_edit,
|
| 227 |
+
outputs=[editing_panel]
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
# Load initial video on page load
|
| 231 |
+
main_page.load(
|
| 232 |
+
fn=None,
|
| 233 |
+
inputs=current_video_id,
|
| 234 |
+
outputs=None,
|
| 235 |
+
js="""(videoId) => {
|
| 236 |
+
const checkPlayer = setInterval(() => {
|
| 237 |
if (window.ytPlayer && window.ytPlayer.cueVideoById) {
|
| 238 |
+
clearInterval(checkPlayer);
|
| 239 |
window.ytPlayer.cueVideoById(videoId);
|
|
|
|
|
|
|
| 240 |
}
|
| 241 |
+
}, 100);
|
| 242 |
+
}"""
|
| 243 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
main_page.launch(share=True)
|