fffiloni commited on
Commit
5439a6f
·
verified ·
1 Parent(s): 9d69626

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -111,7 +111,27 @@ def video_vision(video_input_path, prompt):
111
  seg_frame = visualize(pred_mask, image_paths[frame_idx], temp_dir)
112
  seg_frames.append(seg_frame)
113
 
114
- return result['prediction'], seg_frames
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  else:
117
  return result['prediction'], None
@@ -164,7 +184,7 @@ with gr.Blocks(analytics_enabled=False) as demo:
164
  submit_video_btn = gr.Button("Submit", scale=1)
165
  with gr.Column():
166
  vid_output_res = gr.Textbox(label="Response")
167
- output_video = gr.Gallery(label="Segmentation")
168
 
169
  submit_video_btn.click(
170
  fn = video_vision,
 
111
  seg_frame = visualize(pred_mask, image_paths[frame_idx], temp_dir)
112
  seg_frames.append(seg_frame)
113
 
114
+ output_video = "output_video.mp4"
115
+
116
+ # Read the first image to get the size (resolution)
117
+ frame = cv2.imread(seg_fraes[0])
118
+ height, width, layers = frame.shape
119
+
120
+ # Define the video codec and create VideoWriter object
121
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for MP4
122
+ video = cv2.VideoWriter(output_video, fourcc, 24.0, (width, height))
123
+
124
+ # Iterate over the image paths and write to the video
125
+ for img_path in images:
126
+ frame = cv2.imread(img_path)
127
+ video.write(frame)
128
+
129
+ # Release the video writer
130
+ video.release()
131
+
132
+ print(f"Video created successfully at {output_video}")
133
+
134
+ return result['prediction'], output_video
135
 
136
  else:
137
  return result['prediction'], None
 
184
  submit_video_btn = gr.Button("Submit", scale=1)
185
  with gr.Column():
186
  vid_output_res = gr.Textbox(label="Response")
187
+ output_video = gr.Video(label="Segmentation")
188
 
189
  submit_video_btn.click(
190
  fn = video_vision,