TashiKP commited on
Commit
dd7d891
·
verified ·
1 Parent(s): 0469c68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -10,13 +10,15 @@ import shutil
10
  model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt')
11
 
12
  def detect_video(video):
13
- # Create a temporary file to save the video
14
- with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
15
- tmpfile.write(video.read()) # Save the uploaded video to the temp file
16
- video_path = tmpfile.name # Get the temporary file path
17
-
18
- cap = cv2.VideoCapture(video_path) # Open the temporary video file
 
19
 
 
20
 
21
  # List to hold results
22
  detection_results = []
 
10
  model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt')
11
 
12
  def detect_video(video):
13
+ # Check if the video is in bytes (Gradio typically passes it as bytes)
14
+ if isinstance(video, bytes):
15
+ with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
16
+ tmpfile.write(video) # Write the bytes to the temp file
17
+ video_path = tmpfile.name # Get the temp file path
18
+ else:
19
+ video_path = video # In case it's already a file path
20
 
21
+ cap = cv2.VideoCapture(video_path) # Open the temporary video file
22
 
23
  # List to hold results
24
  detection_results = []