Khalida1w commited on
Commit
5e76035
1 Parent(s): 1d9c414

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -12,7 +12,7 @@ def check_ffmpeg():
12
  if shutil.which("ffmpeg") is None:
13
  raise EnvironmentError("ffmpeg is not installed or not found in the system PATH. Please install ffmpeg to proceed.")
14
 
15
- def process_video(video_path):
16
  # Check if ffmpeg is installed
17
  check_ffmpeg()
18
 
@@ -46,17 +46,26 @@ def process_video(video_path):
46
  if not matched_mp4_files:
47
  raise Exception(f"No .mp4 video files found in directory {output_dir} after conversion for {video_name}.")
48
 
49
- # Return the first video file found (should correspond to the latest processed video)
50
- return matched_mp4_files[0]
 
 
 
 
 
 
 
 
51
 
52
  # Define Gradio inputs
53
  video_input = gr.Video()
 
54
 
55
  video_interface = gr.Interface(
56
  fn=process_video,
57
- inputs=video_input,
58
- outputs="video", # Display the video output
59
- description="YOLO Video Tracking"
60
  )
61
 
62
  # Deploy the interface with share enabled
 
12
  if shutil.which("ffmpeg") is None:
13
  raise EnvironmentError("ffmpeg is not installed or not found in the system PATH. Please install ffmpeg to proceed.")
14
 
15
+ def process_video(video_path, output_option):
16
  # Check if ffmpeg is installed
17
  check_ffmpeg()
18
 
 
46
  if not matched_mp4_files:
47
  raise Exception(f"No .mp4 video files found in directory {output_dir} after conversion for {video_name}.")
48
 
49
+ # Count the number of objects detected
50
+ object_count = len(results.pandas().xyxy[0])
51
+
52
+ # Determine the output based on user's choice
53
+ if output_option == "Count":
54
+ return object_count
55
+ elif output_option == "Video":
56
+ return matched_mp4_files[0]
57
+ elif output_option == "Both":
58
+ return object_count, matched_mp4_files[0]
59
 
60
  # Define Gradio inputs
61
  video_input = gr.Video()
62
+ output_option_input = gr.Radio(choices=["Count", "Video", "Both"], label="Select output type")
63
 
64
  video_interface = gr.Interface(
65
  fn=process_video,
66
+ inputs=[video_input, output_option_input],
67
+ outputs=[gr.Textbox(label="Object Count"), "video"], # Update outputs to support multiple types
68
+ description="YOLO Video Tracking with Output Options"
69
  )
70
 
71
  # Deploy the interface with share enabled