hasanbasbunar commited on
Commit
8f0a7b7
·
verified ·
1 Parent(s): 8e127b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -269,6 +269,13 @@ def process_video_tracker_wrapper(video_path, first_frame_click, max_frames, tim
269
  # Appel de la fonction GPU avec des entiers
270
  return process_video_tracker_gpu(video_path, x, y, max_frames, timeout_seconds)
271
 
 
 
 
 
 
 
 
272
  # --- INTERFACE GRADIO ---
273
 
274
  with gr.Blocks(title="SAM3 Ultimate Suite") as demo:
@@ -329,26 +336,35 @@ with gr.Blocks(title="SAM3 Ultimate Suite") as demo:
329
 
330
  # TAB 4 : VIDEO + TRACKER
331
  with gr.Tab("🎯 Video - Visual Tracker"):
332
- gr.Markdown("### Track a specific object in video\n1. Upload a video.\n2. Wait for the first frame to appear below.\n3. Click on the object you want to track.\n4. Start tracking.")
333
  with gr.Row():
334
  with gr.Column():
335
  v4_input = gr.Video(label="Input Video", format="mp4")
336
  v4_frame0 = gr.Image(label="First Frame (Click the object here)", interactive=True)
337
  v4_max_frames = gr.Slider(10, 300, value=50, step=10, label="Max Frames to Process")
338
- # Ajout choix durée
339
  v4_duration = gr.Radio([60, 120], value=60, label="Max Processing Time (seconds)", info="Choose 60s for short clips, 120s for complex tasks")
340
- v4_btn = gr.Button("Start Object Tracking", variant="primary")
 
 
341
  with gr.Column():
342
  v4_output = gr.Video(label="Result Video")
343
  v4_status = gr.Textbox(label="Status")
344
 
345
  v4_input.change(get_first_frame, inputs=v4_input, outputs=v4_frame0)
346
  click_state = gr.State()
347
- def save_click(evt: gr.SelectData): return evt
348
- v4_frame0.select(save_click, None, click_state)
349
 
350
- # APPEL DU WRAPPER CPU, PAS DE LA FONCTION GPU DIRECTEMENT
 
 
 
 
 
 
 
351
  v4_btn.click(process_video_tracker_wrapper, [v4_input, click_state, v4_max_frames, v4_duration], [v4_output, v4_status])
 
 
 
352
 
353
  if __name__ == "__main__":
354
  demo.launch(share=False, debug=True, theme=gr.themes.Soft())
 
269
  # Appel de la fonction GPU avec des entiers
270
  return process_video_tracker_gpu(video_path, x, y, max_frames, timeout_seconds)
271
 
272
+ # NOUVEAU WRAPPER POUR L'AUTO-START (Select Event)
273
+ def video_select_trigger(video_path, max_frames, duration, evt: gr.SelectData):
274
+ # On lance le traitement directement avec l'event du clic
275
+ output_video, status = process_video_tracker_wrapper(video_path, evt, max_frames, duration)
276
+ # On retourne aussi l'event pour mettre à jour le state "click_state" au cas où
277
+ return output_video, status, evt
278
+
279
  # --- INTERFACE GRADIO ---
280
 
281
  with gr.Blocks(title="SAM3 Ultimate Suite") as demo:
 
336
 
337
  # TAB 4 : VIDEO + TRACKER
338
  with gr.Tab("🎯 Video - Visual Tracker"):
339
+ gr.Markdown("### Track a specific object in video\n1. Upload a video.\n2. Wait for the first frame to appear below.\n3. Click on the object you want to track.\n4. Processing starts automatically.")
340
  with gr.Row():
341
  with gr.Column():
342
  v4_input = gr.Video(label="Input Video", format="mp4")
343
  v4_frame0 = gr.Image(label="First Frame (Click the object here)", interactive=True)
344
  v4_max_frames = gr.Slider(10, 300, value=50, step=10, label="Max Frames to Process")
 
345
  v4_duration = gr.Radio([60, 120], value=60, label="Max Processing Time (seconds)", info="Choose 60s for short clips, 120s for complex tasks")
346
+ with gr.Row():
347
+ v4_btn = gr.Button("Start Object Tracking", variant="primary")
348
+ v4_clear = gr.Button("Reset Tracking") # Nouveau bouton Reset
349
  with gr.Column():
350
  v4_output = gr.Video(label="Result Video")
351
  v4_status = gr.Textbox(label="Status")
352
 
353
  v4_input.change(get_first_frame, inputs=v4_input, outputs=v4_frame0)
354
  click_state = gr.State()
 
 
355
 
356
+ # AUTO-START : Le clic déclenche directement le tracking + sauvegarde l'état
357
+ v4_frame0.select(
358
+ video_select_trigger,
359
+ inputs=[v4_input, v4_max_frames, v4_duration],
360
+ outputs=[v4_output, v4_status, click_state]
361
+ )
362
+
363
+ # Bouton manuel (utilise l'état sauvegardé par le clic)
364
  v4_btn.click(process_video_tracker_wrapper, [v4_input, click_state, v4_max_frames, v4_duration], [v4_output, v4_status])
365
+
366
+ # Bouton Reset
367
+ v4_clear.click(lambda: (None, "", None), outputs=[v4_output, v4_status, click_state])
368
 
369
  if __name__ == "__main__":
370
  demo.launch(share=False, debug=True, theme=gr.themes.Soft())