gangweix commited on
Commit
500548f
·
verified ·
1 Parent(s): 7020001

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -3,6 +3,7 @@ import cv2
3
  import matplotlib
4
  import numpy as np
5
  import os
 
6
  from PIL import Image
7
  import torch
8
  import torch.nn.functional as F
@@ -11,6 +12,7 @@ import trimesh
11
  import tempfile
12
  import shutil
13
  from pathlib import Path
 
14
  from gradio_imageslider import ImageSlider
15
  from huggingface_hub import hf_hub_download
16
 
@@ -93,6 +95,18 @@ def main(share=True):
93
  metric_depth[~mask] = metric_depth[mask].max()
94
  return metric_depth, mask, intrinsics
95
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  def on_submit(image, denoise_steps, apply_filter, request: gr.Request = None):
97
 
98
  H, W = image.shape[:2]
@@ -157,21 +171,19 @@ def main(share=True):
157
  vis_path = os.path.join(output_path, 'image_depth_vis.png')
158
  cv2.imwrite(vis_path, combined_result)
159
 
160
- # tmp_concat = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
161
- # cv2.imwrite(tmp_concat.name, combined_result)
162
-
163
- # download_files = [tmp_concat.name, tmp_raw_depth.name, tmp_ply.name]
164
  file_names = ["image_depth_vis.png", "raw_depth.npy", "pointcloud.ply"]
 
 
 
 
165
  download_files = [
166
  (output_path / name).as_posix()
167
  for name in file_names
168
  if (output_path / name).exists()
169
  ]
170
- # download_files = [vis_path, raw_depth_path, pointcloud_path]
171
 
172
  return [(image, colored_depth), glb_path, download_files]
173
 
174
- # return [(image, colored_depth), tmp_glb.name, tmp_concat.name, tmp_raw_depth.name, tmp_ply.name]
175
 
176
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
177
  gr.Markdown(title)
 
3
  import matplotlib
4
  import numpy as np
5
  import os
6
+ import time
7
  from PIL import Image
8
  import torch
9
  import torch.nn.functional as F
 
12
  import tempfile
13
  import shutil
14
  from pathlib import Path
15
+ from concurrent.futures import ThreadPoolExecutor
16
  from gradio_imageslider import ImageSlider
17
  from huggingface_hub import hf_hub_download
18
 
 
95
  metric_depth[~mask] = metric_depth[mask].max()
96
  return metric_depth, mask, intrinsics
97
 
98
+ def delete_later(path: Union[str, os.PathLike], delay: int = 300):
99
+ def _delete():
100
+ try:
101
+ os.remove(path)
102
+ except FileNotFoundError:
103
+ pass
104
+ def _wait_and_delete():
105
+ time.sleep(delay)
106
+ _delete(path)
107
+ thread_pool_executor.submit(_wait_and_delete)
108
+ atexit.register(_delete)
109
+
110
  def on_submit(image, denoise_steps, apply_filter, request: gr.Request = None):
111
 
112
  H, W = image.shape[:2]
 
171
  vis_path = os.path.join(output_path, 'image_depth_vis.png')
172
  cv2.imwrite(vis_path, combined_result)
173
 
 
 
 
 
174
  file_names = ["image_depth_vis.png", "raw_depth.npy", "pointcloud.ply"]
175
+
176
+ for f in file_names:
177
+ delete_later(output_path / f)
178
+
179
  download_files = [
180
  (output_path / name).as_posix()
181
  for name in file_names
182
  if (output_path / name).exists()
183
  ]
 
184
 
185
  return [(image, colored_depth), glb_path, download_files]
186
 
 
187
 
188
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
189
  gr.Markdown(title)