perler commited on
Commit
5f42443
1 Parent(s): b5ab04b

apparently can't render point clouds anyway, go right to reconstruction

Browse files
Files changed (1) hide show
  1. app.py +51 -48
app.py CHANGED
@@ -11,18 +11,22 @@ import spaces
11
 
12
 
13
  @spaces.GPU(duration=60 * 3)
14
- def run_on_gpu(input_point_cloud_viewer,
15
  gen_resolution_global,
16
  padding_factor,
17
  gen_subsample_manifold_iter,
18
  gen_refine_iter):
19
  print('Started inference at {}'.format(datetime.datetime.now()))
 
 
 
 
20
 
21
  import os
22
  os.chdir(os.path.dirname('./ppsurf'))
23
 
24
- in_file = 'data/{}'.format(input_point_cloud_viewer)
25
- out_file = 'results/rec/{}'.format(input_point_cloud_viewer)
26
 
27
  call_base = ['python', 'pps.py', 'rec']
28
  call_args = [in_file,
@@ -58,36 +62,36 @@ def main():
58
  Inference takes about 2 minutes.
59
  '''
60
 
61
- def convert_to_ply(input_point_cloud_upload: gr.utils.NamedString):
62
-
63
- # add absolute path to import dirs
64
- import sys
65
- import os
66
- sys.path.append(os.path.abspath('ppsurf'))
67
-
68
- # import os
69
- # os.chdir('ppsurf')
70
-
71
- print('Inputs:', input_point_cloud_upload, type(input_point_cloud_upload))
72
- input_shape: str = input_point_cloud_upload.name
73
- if not input_shape.endswith('.ply'):
74
- # load file
75
- from ppsurf.source.occupancy_data_module import OccupancyDataModule
76
- pts_np = OccupancyDataModule.load_pts(input_shape)
77
-
78
- # convert to ply
79
- import trimesh
80
- mesh = trimesh.Trimesh(vertices=pts_np[:, :3])
81
- input_shape = input_shape + '.ply'
82
- mesh.export(input_shape)
83
-
84
- print('ls\n', subprocess.check_output(['ls', os.path.dirname(input_shape)]))
85
-
86
- # show in viewer
87
- print(type(input_tabs))
88
- print(type(input_point_cloud_viewer))
89
- input_tabs.selected = 'pc_viewer'
90
- input_point_cloud_viewer.value = input_shape
91
 
92
  if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
93
  description += (f'\n<p>For faster inference without waiting in queue, '
@@ -100,20 +104,19 @@ def main():
100
  gr.Markdown(description)
101
  with gr.Row():
102
  with gr.Column():
103
- with gr.Tabs() as input_tabs:
104
- with gr.TabItem(label='Input Point Cloud Upload', id='pc_upload'):
105
- input_point_cloud_upload = gr.File(
106
- show_label=False, file_count='single')
107
- input_point_cloud_upload.upload(
108
- fn=convert_to_ply,
109
- inputs=[
110
- input_point_cloud_upload,
111
- ],
112
- outputs=[
113
- # input_point_cloud_viewer, # not available here
114
- ])
115
- with gr.TabItem(label='Input Point Cloud Viewer', id='pc_viewer'):
116
- input_point_cloud_viewer = gr.Model3D(show_label=False)
117
  gen_resolution_global = gr.Slider(
118
  label='Grid Resolution (larger for more details)',
119
  minimum=17, maximum=513, value=129, step=2)
@@ -159,7 +162,7 @@ def main():
159
 
160
  run_button.click(fn=run_on_gpu,
161
  inputs=[
162
- input_point_cloud_viewer,
163
  gen_resolution_global,
164
  padding_factor,
165
  gen_subsample_manifold_iter,
 
11
 
12
 
13
  @spaces.GPU(duration=60 * 3)
14
+ def run_on_gpu(input_point_cloud: gr.utils.NamedString,
15
  gen_resolution_global,
16
  padding_factor,
17
  gen_subsample_manifold_iter,
18
  gen_refine_iter):
19
  print('Started inference at {}'.format(datetime.datetime.now()))
20
+ print('Inputs:', input_point_cloud, gen_resolution_global, padding_factor,
21
+ gen_subsample_manifold_iter, gen_refine_iter)
22
+ print('Types:', type(input_point_cloud), type(gen_resolution_global), type(padding_factor),
23
+ type(gen_subsample_manifold_iter), type(gen_refine_iter))
24
 
25
  import os
26
  os.chdir(os.path.dirname('./ppsurf'))
27
 
28
+ in_file = 'data/{}'.format(input_point_cloud.name)
29
+ out_file = 'results/rec/{}'.format(input_point_cloud.name)
30
 
31
  call_base = ['python', 'pps.py', 'rec']
32
  call_args = [in_file,
 
62
  Inference takes about 2 minutes.
63
  '''
64
 
65
+ # def convert_to_ply(input_point_cloud_upload: gr.utils.NamedString):
66
+ #
67
+ # # add absolute path to import dirs
68
+ # import sys
69
+ # import os
70
+ # sys.path.append(os.path.abspath('ppsurf'))
71
+ #
72
+ # # import os
73
+ # # os.chdir('ppsurf')
74
+ #
75
+ # print('Inputs:', input_point_cloud_upload, type(input_point_cloud_upload))
76
+ # input_shape: str = input_point_cloud_upload.name
77
+ # if not input_shape.endswith('.ply'):
78
+ # # load file
79
+ # from ppsurf.source.occupancy_data_module import OccupancyDataModule
80
+ # pts_np = OccupancyDataModule.load_pts(input_shape)
81
+ #
82
+ # # convert to ply
83
+ # import trimesh
84
+ # mesh = trimesh.Trimesh(vertices=pts_np[:, :3])
85
+ # input_shape = input_shape + '.ply'
86
+ # mesh.export(input_shape)
87
+ #
88
+ # print('ls:\n', subprocess.run(['ls', os.path.dirname(input_shape)]))
89
+ #
90
+ # # show in viewer
91
+ # print(type(input_tabs))
92
+ # # print(type(input_point_cloud_viewer))
93
+ # # input_tabs.selected = 'pc_viewer'
94
+ # # input_point_cloud_viewer.value = input_shape
95
 
96
  if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
97
  description += (f'\n<p>For faster inference without waiting in queue, '
 
104
  gr.Markdown(description)
105
  with gr.Row():
106
  with gr.Column():
107
+ # with gr.Tabs() as input_tabs:
108
+ # with gr.TabItem(label='Input Point Cloud Upload', id='pc_upload'):
109
+ input_point_cloud_upload = gr.File(show_label=False, file_count='single')
110
+ # input_point_cloud_upload.upload(
111
+ # fn=convert_to_ply,
112
+ # inputs=[
113
+ # input_point_cloud_upload,
114
+ # ],
115
+ # outputs=[
116
+ # # input_point_cloud_viewer, # not available here
117
+ # ])
118
+ # with gr.TabItem(label='Input Point Cloud Viewer', id='pc_viewer'):
119
+ # input_point_cloud_viewer = gr.Model3D(show_label=False)
 
120
  gen_resolution_global = gr.Slider(
121
  label='Grid Resolution (larger for more details)',
122
  minimum=17, maximum=513, value=129, step=2)
 
162
 
163
  run_button.click(fn=run_on_gpu,
164
  inputs=[
165
+ input_point_cloud_upload,
166
  gen_resolution_global,
167
  padding_factor,
168
  gen_subsample_manifold_iter,