maryna7679 commited on
Commit
3ff48b9
·
1 Parent(s): 0c936fa
Files changed (2) hide show
  1. Resources/css.py +2 -19
  2. app.py +117 -109
Resources/css.py CHANGED
@@ -1,21 +1,4 @@
1
- <<<<<<< HEAD:Resources/css.py
2
  css = """
3
- .container {
4
- position: relative;
5
- width: 100%;
6
- height: 0;
7
- padding-bottom: 56.25%;
8
  }
9
- .video {
10
- position: absolute;
11
- top: 0;
12
- left: 0;
13
- width: 100%;
14
- height: 100%;
15
- }"""
16
- =======
17
- css = """
18
- #yt-container {
19
- }
20
- """
21
- >>>>>>> main:Pages/Resources/css.py
 
 
1
  css = """
2
+ #yt-container {
 
 
 
 
3
  }
4
+ """
 
 
 
 
 
 
 
 
 
 
 
 
app.py CHANGED
@@ -1,9 +1,9 @@
1
  import gradio as gr
2
  import pandas as pd
3
- from .Functions.video_player_functions import youtube_link_to_id, get_video_embed_by_id, get_video_link_by_pointer, get_youtube_player_html
4
- from .Functions.caption_editor_functions import get_captions_by_video_id, save_dataframe
5
- from .Resources.css import css
6
- from .Resources.js import yt_init_js
7
 
8
  next_video_pointer = 0
9
  user = ""
@@ -116,115 +116,123 @@ with gr.Blocks(css=css, head=yt_init_js) as main_page:
116
  gr.Markdown("## Caption Editor")
117
  gr.LoginButton()
118
 
 
119
  current_video_id = gr.Textbox(value=start_video_id, visible=False, interactive=False)
120
  current_captions_full = gr.DataFrame(value=start_captions_full, visible=False, interactive=False)
121
  selected_row_idx = gr.Number(value=-1, visible=False)
122
-
123
- with gr.Row():
124
- with gr.Column(scale=2, min_width=600):
125
- # Video player and "next video button
126
- video_embed = gr.HTML(value=get_youtube_player_html())
127
- next_video_button = gr.Button("Next")
128
- with gr.Column(scale=1, min_width=200):
129
- # Read-only DataFrame with add button
130
- caption_editor = gr.DataFrame(interactive=False,
131
- elem_id="tbl",
132
- value=start_captions,
133
- datatype=["number", "str", "number"],
134
- col_count=(3, "fixed"),
135
- column_widths=["20%", "60%", "20%"],
136
- headers=["Start", "Text", "End"],
137
- wrap=True)
138
- add_entry_button = gr.Button("Add Entry", variant="secondary")
139
-
140
- with gr.Row():
141
- # Editing panel (initially hidden) - spans full width
142
- with gr.Group(visible=False) as editing_panel:
143
- gr.Markdown("### Edit Caption Entry")
144
- with gr.Row(equal_height=False):
145
- with gr.Column():
146
- start_time_input = gr.Textbox(label="Start Time (seconds)", value="0.000", interactive=False)
147
- insert_start_time_button = gr.Button("Insert Current Time")
148
- with gr.Column():
149
- text_input = gr.Textbox(label="Caption Text", placeholder="Enter caption text...")
150
-
151
- with gr.Column():
152
- end_time_input = gr.Textbox(label="End Time (seconds)", value="0.000", interactive=False)
153
- insert_end_time_button = gr.Button("Insert Current Time")
154
-
155
- with gr.Row(equal_height=False):
156
- save_entry_button = gr.Button("Save Entry", variant="primary")
157
- cancel_button = gr.Button("Cancel", variant="secondary")
158
-
159
- save_result = gr.Markdown()
160
 
161
- # Event handlers
162
- next_video_button.click(
163
- fn=get_next_components,
164
- outputs=[caption_editor, current_captions_full, current_video_id]
165
- )
166
-
167
- # Load video when current_video_id changes
168
- current_video_id.change(
169
- fn=None,
170
- inputs=current_video_id,
171
- outputs=None,
172
- js="""(videoId) => {
173
- if (window.ytPlayer && window.ytPlayer.cueVideoById) {
174
- console.log('[Video Load] Calling cueVideoById with:', videoId);
175
- window.ytPlayer.cueVideoById(videoId);
176
- } else {
177
- console.error('[Video Load] Player not ready yet');
178
- }
179
- }"""
180
- )
181
-
182
- # Handle row selection in DataFrame
183
- caption_editor.select(
184
- fn=on_row_select,
185
- inputs=[caption_editor],
186
- outputs=[editing_panel, start_time_input, text_input, end_time_input, selected_row_idx, save_entry_button]
187
- )
188
-
189
- # Handle add entry button
190
- add_entry_button.click(
191
- fn=show_add_entry_form,
192
- outputs=[editing_panel, start_time_input, text_input, end_time_input, selected_row_idx, save_entry_button]
193
- )
194
-
195
- # Handle save entry
196
- save_entry_button.click(
197
- fn=save_entry,
198
- inputs=[caption_editor, start_time_input, text_input, end_time_input, selected_row_idx, current_video_id, current_captions_full],
199
- outputs=[caption_editor, editing_panel, save_result]
200
- )
 
 
 
 
 
 
 
 
 
 
201
 
202
- insert_start_time_button.click(fn=None, inputs=None, outputs=start_time_input,
203
- js="() => window.ytPlayer ? +window.ytPlayer.getCurrentTime().toFixed(3) : 0")
 
 
 
 
 
 
 
 
 
 
 
 
204
 
205
- insert_end_time_button.click(fn=None, inputs=None, outputs=end_time_input,
206
- js="() => window.ytPlayer ? +window.ytPlayer.getCurrentTime().toFixed(3) : 0")
 
 
 
 
207
 
208
-
209
- # Handle cancel
210
- cancel_button.click(
211
- fn=cancel_edit,
212
- outputs=[editing_panel]
213
- )
214
-
215
- # Load initial video on page load
216
- main_page.load(
217
- fn=None,
218
- inputs=current_video_id,
219
- outputs=None,
220
- js="""(videoId) => {
221
- const checkPlayer = setInterval(() => {
222
- if (window.ytPlayer && window.ytPlayer.cueVideoById) {
223
- clearInterval(checkPlayer);
224
- window.ytPlayer.cueVideoById(videoId);
225
- }
226
- }, 100);
227
- }"""
228
- )
229
-
230
- main_page.load(get_username) # Disabled when auth is disabled
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import pandas as pd
3
+ from Functions.video_player_functions import youtube_link_to_id, get_video_embed_by_id, get_video_link_by_pointer, get_youtube_player_html
4
+ from Functions.caption_editor_functions import get_captions_by_video_id, save_dataframe
5
+ from Resources.css import css
6
+ from Resources.js import yt_init_js
7
 
8
  next_video_pointer = 0
9
  user = ""
 
116
  gr.Markdown("## Caption Editor")
117
  gr.LoginButton()
118
 
119
+ current_user = gr.Textbox(visible=False, interactive=False)
120
  current_video_id = gr.Textbox(value=start_video_id, visible=False, interactive=False)
121
  current_captions_full = gr.DataFrame(value=start_captions_full, visible=False, interactive=False)
122
  selected_row_idx = gr.Number(value=-1, visible=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.load(share=True, ssr_mode=False)