lemonaddie commited on
Commit
ede989c
1 Parent(s): a91071a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -74
app.py CHANGED
@@ -22,11 +22,6 @@ def process(
22
  path_out_16bit=None,
23
  path_out_fp32=None,
24
  path_out_vis=None,
25
- _input_3d_plane_near=None,
26
- _input_3d_plane_far=None,
27
- _input_3d_embossing=None,
28
- _input_3d_filter_size=None,
29
- _input_3d_frame_near=None,
30
  ):
31
  if path_out_vis is not None:
32
  return (
@@ -67,75 +62,6 @@ def process(
67
  )
68
 
69
 
70
- def process_3d(
71
- input_image,
72
- files,
73
- size_longest_px,
74
- size_longest_cm,
75
- filter_size,
76
- plane_near,
77
- plane_far,
78
- embossing,
79
- frame_thickness,
80
- frame_near,
81
- frame_far,
82
- ):
83
- if input_image is None or len(files) < 1:
84
- raise gr.Error("Please upload an image (or use examples) and compute depth first")
85
-
86
- if plane_near >= plane_far:
87
- raise gr.Error("NEAR plane must have a value smaller than the FAR plane")
88
-
89
- def _process_3d(size_longest_px, filter_size, vertex_colors, scene_lights, output_model_scale=None):
90
- image_rgb = input_image
91
- image_depth = files[0]
92
-
93
- image_rgb_basename, image_rgb_ext = os.path.splitext(image_rgb)
94
- image_depth_basename, image_depth_ext = os.path.splitext(image_depth)
95
-
96
- image_rgb_content = Image.open(image_rgb)
97
- image_rgb_w, image_rgb_h = image_rgb_content.width, image_rgb_content.height
98
- image_rgb_d = max(image_rgb_w, image_rgb_h)
99
- image_new_w = size_longest_px * image_rgb_w // image_rgb_d
100
- image_new_h = size_longest_px * image_rgb_h // image_rgb_d
101
-
102
- image_rgb_new = image_rgb_basename + f"_{size_longest_px}" + image_rgb_ext
103
- image_depth_new = image_depth_basename + f"_{size_longest_px}" + image_depth_ext
104
- image_rgb_content.resize((image_new_w, image_new_h), Image.LANCZOS).save(
105
- image_rgb_new
106
- )
107
- Image.open(image_depth).resize((image_new_w, image_new_h), Image.LANCZOS).save(
108
- image_depth_new
109
- )
110
-
111
- path_glb, path_stl = extrude_depth_3d(
112
- image_rgb_new,
113
- image_depth_new,
114
- output_model_scale=size_longest_cm * 10 if output_model_scale is None else output_model_scale,
115
- filter_size=filter_size,
116
- coef_near=plane_near,
117
- coef_far=plane_far,
118
- emboss=embossing / 100,
119
- f_thic=frame_thickness / 100,
120
- f_near=frame_near / 100,
121
- f_back=frame_far / 100,
122
- vertex_colors=vertex_colors,
123
- scene_lights=scene_lights,
124
- )
125
-
126
- return path_glb, path_stl
127
-
128
- path_viewer_glb, _ = _process_3d(256, filter_size, vertex_colors=False, scene_lights=True, output_model_scale=1)
129
- path_files_glb, path_files_stl = _process_3d(size_longest_px, filter_size, vertex_colors=True, scene_lights=False)
130
-
131
- # sanitize 3d viewer glb path to keep babylon.js happy
132
- path_viewer_glb_sanitized = os.path.join(os.path.dirname(path_viewer_glb), "preview.glb")
133
- if path_viewer_glb_sanitized != path_viewer_glb:
134
- os.rename(path_viewer_glb, path_viewer_glb_sanitized)
135
- path_viewer_glb = path_viewer_glb_sanitized
136
-
137
- return path_viewer_glb, [path_files_glb, path_files_stl]
138
-
139
  @spaces.GPU
140
  def run_demo_server(pipe):
141
  process_pipe = functools.partial(process, pipe)
 
22
  path_out_16bit=None,
23
  path_out_fp32=None,
24
  path_out_vis=None,
 
 
 
 
 
25
  ):
26
  if path_out_vis is not None:
27
  return (
 
62
  )
63
 
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  @spaces.GPU
66
  def run_demo_server(pipe):
67
  process_pipe = functools.partial(process, pipe)