nagasurendra commited on
Commit
79226f5
·
verified ·
1 Parent(s): a00788d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -17
app.py CHANGED
@@ -23,11 +23,6 @@ def process_video(video):
23
  new_width, new_height = 640, 480 # Resize to 640x480 resolution
24
  frame_width, frame_height = new_width, new_height
25
 
26
- # List to store processed frames for Gradio output
27
- processed_frames = []
28
-
29
- frame_counter = 0 # Counter to limit the number of frames for processing
30
-
31
  while True:
32
  # Read a frame from the video
33
  ret, frame = input_video.read()
@@ -48,26 +43,18 @@ def process_video(video):
48
  # Convert the annotated frame to RGB format for displaying
49
  annotated_frame_rgb = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
50
 
51
- # Append the annotated frame to the list for Gradio
52
- processed_frames.append(annotated_frame_rgb)
53
-
54
- # Limit the number of frames processed (to speed up processing)
55
- frame_counter += 1
56
- if frame_counter > 100: # Process only 100 frames, adjust as necessary
57
- break
58
 
59
  # Release resources
60
  input_video.release()
61
 
62
- # Return the processed frames as a list of NumPy arrays (Gradio expects this format)
63
- return processed_frames # Ensure this is a list of frames
64
-
65
  # Create a Gradio interface for video upload
66
  iface = gr.Interface(fn=process_video,
67
  inputs=gr.Video(label="Upload Video"), # Updated line
68
- outputs=gr.Video(label="Processed Video"), # This will display the output video directly
69
  title="YOLOv8 Object Detection - Real-Time Display",
70
- description="Upload a video for object detection using YOLOv8. The frames with detections will be shown in real-time.")
71
 
72
  # Launch the interface
73
  iface.launch()
 
23
  new_width, new_height = 640, 480 # Resize to 640x480 resolution
24
  frame_width, frame_height = new_width, new_height
25
 
 
 
 
 
 
26
  while True:
27
  # Read a frame from the video
28
  ret, frame = input_video.read()
 
43
  # Convert the annotated frame to RGB format for displaying
44
  annotated_frame_rgb = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
45
 
46
+ # Yield the frame immediately
47
+ yield annotated_frame_rgb
 
 
 
 
 
48
 
49
  # Release resources
50
  input_video.release()
51
 
 
 
 
52
  # Create a Gradio interface for video upload
53
  iface = gr.Interface(fn=process_video,
54
  inputs=gr.Video(label="Upload Video"), # Updated line
55
+ outputs=gr.Image(label="Processed Frame", type="numpy"), # Show processed frame immediately
56
  title="YOLOv8 Object Detection - Real-Time Display",
57
+ description="Upload a video for object detection using YOLOv8. The frames with detections will be shown in real-time as they are processed.")
58
 
59
  # Launch the interface
60
  iface.launch()