maryna7679 commited on
Commit
d94db10
·
1 Parent(s): 780e75e

No login test

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