maryna7679 commited on
Commit
f4f04e7
·
1 Parent(s): c63553c

Render test 4

Browse files
Files changed (1) hide show
  1. app.py +105 -105
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.Blocks(css=css, head=yt_init_js) as editor_page:
137
- with gr.Row():
138
- with gr.Column(scale=2, min_width=600):
139
- # Video player and "next video button
140
- video_embed = gr.HTML(value=get_youtube_player_html())
141
- next_video_button = gr.Button("Next")
142
- with gr.Column(scale=1, min_width=200):
143
- # Read-only DataFrame with add button
144
- caption_editor = gr.DataFrame(interactive=False,
145
- elem_id="tbl",
146
- value=start_captions,
147
- datatype=["number", "str", "number"],
148
- col_count=(3, "fixed"),
149
- column_widths=["20%", "60%", "20%"],
150
- headers=["Start", "Text", "End"],
151
- wrap=True)
152
- add_entry_button = gr.Button("Add Entry", variant="secondary")
153
-
154
- with gr.Row():
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
- 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)