Spaces:
Sleeping
Sleeping
updates
Browse files
app.py
CHANGED
@@ -238,91 +238,90 @@ def create_interface():
|
|
238 |
success = annotator.load_videos_from_hf()
|
239 |
|
240 |
if not success:
|
241 |
-
logger.error("Failed to load videos.
|
242 |
-
#
|
243 |
|
244 |
with gr.Blocks() as demo:
|
245 |
gr.Markdown("# Cricket Video Annotation Tool")
|
246 |
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
with gr.Column():
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
with gr.Column():
|
268 |
-
for category, options in list(ANNOTATION_CATEGORIES.items())[4:]:
|
269 |
radio = gr.Radio(
|
270 |
choices=options,
|
271 |
label=category,
|
272 |
-
info=f"Select {category}"
|
273 |
)
|
274 |
annotation_components.append(radio)
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
# --- Start Edit: Add a Textbox for status messages from next/prev ---
|
282 |
-
status_textbox = gr.Textbox(label="Status", interactive=False)
|
283 |
# --- End Edit ---
|
284 |
-
|
285 |
-
|
|
|
286 |
current_video = annotator.get_current_video()
|
287 |
if current_video:
|
288 |
-
logger.info(f"Setting video player
|
289 |
-
video_player.
|
290 |
-
|
291 |
-
#
|
|
|
292 |
existing_annotations = annotator.load_existing_annotation()
|
293 |
if existing_annotations:
|
294 |
logger.info(f"Loading existing annotations: {existing_annotations}")
|
295 |
-
for
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
|
|
|
|
|
|
|
|
|
|
300 |
save_btn.click(
|
301 |
fn=annotator.save_annotation,
|
302 |
inputs=annotation_components,
|
303 |
-
#
|
304 |
-
outputs=status_textbox # Changed from gr.Textbox(label="Status")
|
305 |
-
# --- End Edit ---
|
306 |
)
|
307 |
-
|
308 |
next_btn.click(
|
309 |
fn=annotator.next_video,
|
310 |
inputs=annotation_components,
|
311 |
-
#
|
312 |
outputs=[video_player] + annotation_components + [status_textbox]
|
313 |
-
# --- End Edit ---
|
314 |
)
|
315 |
-
|
316 |
prev_btn.click(
|
317 |
fn=annotator.prev_video,
|
318 |
inputs=annotation_components,
|
319 |
-
#
|
320 |
outputs=[video_player] + annotation_components + [status_textbox]
|
321 |
-
# --- End Edit ---
|
322 |
)
|
323 |
-
|
324 |
return demo
|
325 |
|
326 |
if __name__ == "__main__":
|
327 |
demo = create_interface()
|
|
|
328 |
demo.launch(allowed_paths=["/"])
|
|
|
238 |
success = annotator.load_videos_from_hf()
|
239 |
|
240 |
if not success:
|
241 |
+
logger.error("Failed to load videos. Interface might not function correctly.")
|
242 |
+
# Handle the error appropriately, maybe show a message in the UI
|
243 |
|
244 |
with gr.Blocks() as demo:
|
245 |
gr.Markdown("# Cricket Video Annotation Tool")
|
246 |
|
247 |
+
# --- Start Edit: Reorganize layout ---
|
248 |
+
with gr.Row(): # Main row to hold video and controls side-by-side
|
249 |
+
with gr.Column(scale=3): # Assign more horizontal space to the video column
|
250 |
+
video_player = gr.Video(
|
251 |
+
value=annotator.get_current_video, # Keep using the function loader
|
252 |
+
label="Current Video", # Add a label for clarity
|
253 |
+
height=500 # Set a fixed height (adjust as needed for your screen)
|
254 |
+
)
|
255 |
+
# Status textbox below the video
|
256 |
+
status_textbox = gr.Textbox(label="Status", interactive=False)
|
257 |
+
|
258 |
+
with gr.Column(scale=2): # Assign less space to the controls column
|
259 |
+
annotation_components = []
|
260 |
+
gr.Markdown("### Annotations") # Header for the annotation section
|
261 |
+
|
262 |
+
# Display annotation radio buttons vertically in this column
|
263 |
+
# You might still need two columns here if vertical space is tight
|
264 |
+
# For simplicity, let's try one column first.
|
265 |
+
for category, options in ANNOTATION_CATEGORIES.items():
|
|
|
|
|
|
|
266 |
radio = gr.Radio(
|
267 |
choices=options,
|
268 |
label=category,
|
269 |
+
# info=f"Select {category}" # Removing info saves a bit of vertical space
|
270 |
)
|
271 |
annotation_components.append(radio)
|
272 |
+
|
273 |
+
# Buttons below the annotations, within the same column
|
274 |
+
with gr.Row():
|
275 |
+
prev_btn = gr.Button("Previous Video")
|
276 |
+
save_btn = gr.Button("Save Annotations", variant="primary")
|
277 |
+
next_btn = gr.Button("Next Video")
|
|
|
|
|
278 |
# --- End Edit ---
|
279 |
+
|
280 |
+
|
281 |
+
# Initialize with first video and potential annotations (logic remains the same)
|
282 |
current_video = annotator.get_current_video()
|
283 |
if current_video:
|
284 |
+
logger.info(f"Setting initial video player value: {current_video}")
|
285 |
+
# The video_player will call annotator.get_current_video on load,
|
286 |
+
# so explicitly setting value might be redundant unless get_current_video changes state.
|
287 |
+
# video_player.value = current_video # Let's rely on the function loader
|
288 |
+
|
289 |
existing_annotations = annotator.load_existing_annotation()
|
290 |
if existing_annotations:
|
291 |
logger.info(f"Loading existing annotations: {existing_annotations}")
|
292 |
+
# Need to return initial values for components if loading annotations
|
293 |
+
# This part is tricky with function loading. Let's adjust.
|
294 |
+
|
295 |
+
# We might need a separate function to load initial state
|
296 |
+
# Or adjust how initial values are set.
|
297 |
+
# For now, let's assume the user starts fresh or loads via next/prev.
|
298 |
+
# A more robust solution might involve a dedicated "load" button or
|
299 |
+
# returning initial component values from a setup function.
|
300 |
+
|
301 |
+
# Event handlers (ensure outputs match the new layout variables)
|
302 |
save_btn.click(
|
303 |
fn=annotator.save_annotation,
|
304 |
inputs=annotation_components,
|
305 |
+
outputs=status_textbox # Output to the status textbox defined earlier
|
|
|
|
|
306 |
)
|
307 |
+
|
308 |
next_btn.click(
|
309 |
fn=annotator.next_video,
|
310 |
inputs=annotation_components,
|
311 |
+
# Outputs: video, clear all radios, update status
|
312 |
outputs=[video_player] + annotation_components + [status_textbox]
|
|
|
313 |
)
|
314 |
+
|
315 |
prev_btn.click(
|
316 |
fn=annotator.prev_video,
|
317 |
inputs=annotation_components,
|
318 |
+
# Outputs: video, clear all radios, update status
|
319 |
outputs=[video_player] + annotation_components + [status_textbox]
|
|
|
320 |
)
|
321 |
+
|
322 |
return demo
|
323 |
|
324 |
if __name__ == "__main__":
|
325 |
demo = create_interface()
|
326 |
+
# Consider adding share=True for easier testing if needed
|
327 |
demo.launch(allowed_paths=["/"])
|