freealise commited on
Commit
6925966
1 Parent(s): 645ddd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -9,12 +9,19 @@ import torch.nn.functional as F
9
  from torchvision import transforms
10
  from torchvision.transforms import Compose
11
  import tempfile
12
- import spaces
 
13
 
14
  from depth_anything.dpt import DepthAnything
15
  from depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
16
  from moviepy.editor import *
17
 
 
 
 
 
 
 
18
  def create_video(frames, fps, type):
19
  print("building video result")
20
  clip = ImageSequenceClip(frames, fps=fps)
@@ -141,11 +148,12 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits'):
141
  count += 1
142
 
143
  final_vid = create_video(depth_frames, frame_rate, "depth")
 
144
  raw_video.release()
145
  # out.release()
146
  cv2.destroyAllWindows()
147
 
148
- return final_vid #output_path
149
 
150
  def loadurl(url):
151
  return url
@@ -200,7 +208,8 @@ with gr.Blocks(css=css) as demo:
200
  submit = gr.Button("Submit")
201
  with gr.Column():
202
  model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
203
- processed_video = gr.Video(label="Processed Video", format="mp4")
 
204
 
205
  def on_submit(uploaded_video,model_type):
206
 
@@ -209,12 +218,12 @@ with gr.Blocks(css=css) as demo:
209
 
210
  return output_video_path
211
 
212
- submit.click(on_submit, inputs=[input_video, model_type], outputs=processed_video)
213
 
214
  example_files = os.listdir('examples')
215
  example_files.sort()
216
  example_files = [os.path.join('examples', filename) for filename in example_files]
217
- examples = gr.Examples(examples=example_files, inputs=[input_video], outputs=processed_video, fn=on_submit, cache_examples=True)
218
 
219
 
220
  if __name__ == '__main__':
 
9
  from torchvision import transforms
10
  from torchvision.transforms import Compose
11
  import tempfile
12
+ import spaces
13
+ from zipfile import ZipFile
14
 
15
  from depth_anything.dpt import DepthAnything
16
  from depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
17
  from moviepy.editor import *
18
 
19
+ def zip_files(files):
20
+ with ZipFile("depth_result.zip", "w") as zipObj:
21
+ for idx, file in enumerate(files):
22
+ zipObj.write(file.name, file.name.split("/")[-1])
23
+ return "depth_result.zip"
24
+
25
  def create_video(frames, fps, type):
26
  print("building video result")
27
  clip = ImageSequenceClip(frames, fps=fps)
 
148
  count += 1
149
 
150
  final_vid = create_video(depth_frames, frame_rate, "depth")
151
+ final_zip = zip_files(depth_frames)
152
  raw_video.release()
153
  # out.release()
154
  cv2.destroyAllWindows()
155
 
156
+ return final_vid, final_zip #output_path
157
 
158
  def loadurl(url):
159
  return url
 
208
  submit = gr.Button("Submit")
209
  with gr.Column():
210
  model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
211
+ processed_video = gr.Video(label="Output Video", format="mp4")
212
+ processed_zip = gr.File(label="Output Archive")
213
 
214
  def on_submit(uploaded_video,model_type):
215
 
 
218
 
219
  return output_video_path
220
 
221
+ submit.click(on_submit, inputs=[input_video, model_type], outputs=[processed_video, processed_zip])
222
 
223
  example_files = os.listdir('examples')
224
  example_files.sort()
225
  example_files = [os.path.join('examples', filename) for filename in example_files]
226
+ examples = gr.Examples(examples=example_files, inputs=[input_video], outputs=[processed_video, processed_zip], fn=on_submit, cache_examples=True)
227
 
228
 
229
  if __name__ == '__main__':