ashu1069 commited on
Commit
dc098c7
·
1 Parent(s): 5048b19
Files changed (1) hide show
  1. app.py +53 -54
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. Using demo mode with sample video.")
242
- # In real app, you might want to provide a sample video or show an error
243
 
244
  with gr.Blocks() as demo:
245
  gr.Markdown("# Cricket Video Annotation Tool")
246
 
247
- with gr.Row():
248
- video_player = gr.Video(
249
- value=annotator.get_current_video, # Function to load the raw video
250
- inputs=[], # No inputs needed for loading the video
251
-
252
- # outputs=gr.Video(label="Current Video") # Output type is video
253
- )
254
-
255
- annotation_components = []
256
-
257
- with gr.Row():
258
- with gr.Column():
259
- for category, options in list(ANNOTATION_CATEGORIES.items())[:4]:
260
- radio = gr.Radio(
261
- choices=options,
262
- label=category,
263
- info=f"Select {category}"
264
- )
265
- annotation_components.append(radio)
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
- with gr.Row():
277
- prev_btn = gr.Button("Previous Video")
278
- save_btn = gr.Button("Save Annotations", variant="primary")
279
- next_btn = gr.Button("Next Video")
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
- # Initialize with first video
 
286
  current_video = annotator.get_current_video()
287
  if current_video:
288
- logger.info(f"Setting video player with video: {current_video}")
289
- video_player.value = current_video
290
-
291
- # Try to load existing annotations
 
292
  existing_annotations = annotator.load_existing_annotation()
293
  if existing_annotations:
294
  logger.info(f"Loading existing annotations: {existing_annotations}")
295
- for i, category in enumerate(ANNOTATION_CATEGORIES.keys()):
296
- if category in existing_annotations:
297
- annotation_components[i].value = existing_annotations[category]
298
-
299
- # Event handlers
 
 
 
 
 
300
  save_btn.click(
301
  fn=annotator.save_annotation,
302
  inputs=annotation_components,
303
- # --- Start Edit: Update output for save button ---
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
- # --- Start Edit: Update outputs for next button ---
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
- # --- Start Edit: Update outputs for prev button ---
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=["/"])