dexpyw commited on
Commit
d7f0de3
·
verified ·
1 Parent(s): 5d8e38e

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -45,8 +45,6 @@ def predict_video(video):
45
  temp_output_path = tempfile.mktemp(suffix=".mp4")
46
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
47
  out = cv2.VideoWriter(temp_output_path, fourcc, fps, (frame_width, frame_height))
48
-
49
- processed_frames = []
50
 
51
  while True:
52
  ret, frame = cap.read()
@@ -55,18 +53,20 @@ def predict_video(video):
55
 
56
  result = detection_model.predict(frame, conf=0.5, iou=0.6)
57
  img_bgr = result[0].plot()
58
- out_frame = img_bgr[..., ::-1]
59
- processed_frames.append(Image.fromarray(out_frame)) # Store frame as PIL image
60
  out.write(out_frame)
61
 
62
  cap.release()
63
  out.release()
 
 
64
  return temp_output_path # Return the path to the processed video
65
 
66
  def enable_button(image_input, video_input):
67
  if image_input is None and video_input is None:
68
  return gr.Button.update(interactive=False)
69
- return gr.Button.update(interactive=True)
 
70
 
71
 
72
  REPO_ID = "dexpyw/model"
@@ -85,7 +85,7 @@ image_interface = gr.Interface(
85
  video_interface = gr.Interface(
86
  fn=predict_video,
87
  inputs=gr.Video(label="Upload Video"),
88
- outputs=gr.Gallery(label="Predicted Video Frames"),
89
  live=False
90
  )
91
 
 
45
  temp_output_path = tempfile.mktemp(suffix=".mp4")
46
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
47
  out = cv2.VideoWriter(temp_output_path, fourcc, fps, (frame_width, frame_height))
 
 
48
 
49
  while True:
50
  ret, frame = cap.read()
 
53
 
54
  result = detection_model.predict(frame, conf=0.5, iou=0.6)
55
  img_bgr = result[0].plot()
56
+ out_frame = img_bgr[..., ::-1] # Convert BGR to RGB
 
57
  out.write(out_frame)
58
 
59
  cap.release()
60
  out.release()
61
+
62
+ # Return the path to the processed video
63
  return temp_output_path # Return the path to the processed video
64
 
65
  def enable_button(image_input, video_input):
66
  if image_input is None and video_input is None:
67
  return gr.Button.update(interactive=False)
68
+ return gr.Button.update(interactive=True)
69
+
70
 
71
 
72
  REPO_ID = "dexpyw/model"
 
85
  video_interface = gr.Interface(
86
  fn=predict_video,
87
  inputs=gr.Video(label="Upload Video"),
88
+ outputs=gr.Video(label="Predicted Video"),
89
  live=False
90
  )
91