Spaces:
Paused
Paused
nicer UI, catch rec errors, try fix rendering mesh by re-enabling tabs
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ def run_on_gpu(input_point_cloud: gr.utils.NamedString,
|
|
| 15 |
gen_resolution_global: int,
|
| 16 |
padding_factor: float,
|
| 17 |
gen_subsample_manifold_iter: int,
|
| 18 |
-
gen_refine_iter: int):
|
| 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)
|
|
@@ -32,7 +32,6 @@ def run_on_gpu(input_point_cloud: gr.utils.NamedString,
|
|
| 32 |
# splitext_result = os.path.splitext(in_file)
|
| 33 |
rand_hash = uuid.uuid4().hex
|
| 34 |
out_dir = '/tmp/outputs/{}'.format(rand_hash)
|
| 35 |
-
# out_file = os.path.join(out_dir, in_file, in_file + '.ply')
|
| 36 |
out_file_basename = os.path.basename(in_file) + '.ply'
|
| 37 |
out_file = os.path.join(out_dir, os.path.basename(in_file), out_file_basename)
|
| 38 |
os.makedirs(out_dir, exist_ok=True)
|
|
@@ -55,34 +54,41 @@ def run_on_gpu(input_point_cloud: gr.utils.NamedString,
|
|
| 55 |
]
|
| 56 |
|
| 57 |
sys.argv = args
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
print('Finished inference at {}'.format(datetime.datetime.now()))
|
| 60 |
|
| 61 |
result_3d_model = out_file
|
| 62 |
-
progress_text = 'done'
|
| 63 |
|
| 64 |
-
return result_3d_model
|
| 65 |
|
| 66 |
|
| 67 |
def main():
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
Supported file formats:
|
| 71 |
- PLY, STL, OBJ and other mesh files,
|
| 72 |
- XYZ as whitespace-separated text file,
|
| 73 |
- NPY and NPZ (key='arr_0'),
|
| 74 |
- LAS and LAZ (version 1.0-1.4), COPC and CRS.
|
| 75 |
Best results for 50k-250k points.
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
This method is meant for scans of single and few objects.
|
| 78 |
Quality for scenes and landscapes will be lower.
|
| 79 |
|
| 80 |
-
Inference takes
|
| 81 |
'''
|
| 82 |
|
| 83 |
# can't render many input types directly in Gradio Model3D
|
| 84 |
# so we need to convert to supported format
|
| 85 |
-
# Gradio can't draw point clouds anyway, so we skip this for now
|
| 86 |
# def convert_to_ply(input_point_cloud_upload: gr.utils.NamedString):
|
| 87 |
#
|
| 88 |
# # add absolute path to import dirs
|
|
@@ -115,17 +121,18 @@ def main():
|
|
| 115 |
# # input_point_cloud_viewer.value = input_shape
|
| 116 |
|
| 117 |
if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
|
| 124 |
with gr.Blocks(css='style.css') as demo:
|
| 125 |
-
gr.Markdown(
|
| 126 |
with gr.Row():
|
| 127 |
with gr.Column():
|
| 128 |
-
|
|
|
|
| 129 |
# with gr.TabItem(label='Input Point Cloud Upload', id='pc_upload'):
|
| 130 |
input_point_cloud_upload = gr.File(show_label=False, file_count='single')
|
| 131 |
# input_point_cloud_upload.upload(
|
|
@@ -151,10 +158,11 @@ def main():
|
|
| 151 |
label='Edge Refinement Iterations (larger for more details)',
|
| 152 |
minimum=3, maximum=30, value=10, step=1)
|
| 153 |
with gr.Column():
|
| 154 |
-
|
| 155 |
-
#
|
| 156 |
-
|
| 157 |
-
|
|
|
|
| 158 |
# with gr.TabItem(label='Output mesh file'):
|
| 159 |
# output_file = gr.File(show_label=False)
|
| 160 |
# with gr.Row():
|
|
@@ -192,7 +200,7 @@ def main():
|
|
| 192 |
outputs=[
|
| 193 |
result_3d_model,
|
| 194 |
# output_file,
|
| 195 |
-
progress_text,
|
| 196 |
])
|
| 197 |
|
| 198 |
demo.queue(max_size=5)
|
|
|
|
| 15 |
gen_resolution_global: int,
|
| 16 |
padding_factor: float,
|
| 17 |
gen_subsample_manifold_iter: int,
|
| 18 |
+
gen_refine_iter: int) -> str:
|
| 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)
|
|
|
|
| 32 |
# splitext_result = os.path.splitext(in_file)
|
| 33 |
rand_hash = uuid.uuid4().hex
|
| 34 |
out_dir = '/tmp/outputs/{}'.format(rand_hash)
|
|
|
|
| 35 |
out_file_basename = os.path.basename(in_file) + '.ply'
|
| 36 |
out_file = os.path.join(out_dir, os.path.basename(in_file), out_file_basename)
|
| 37 |
os.makedirs(out_dir, exist_ok=True)
|
|
|
|
| 54 |
]
|
| 55 |
|
| 56 |
sys.argv = args
|
| 57 |
+
try:
|
| 58 |
+
subprocess.run(['python', 'ppsurf/pps.py'] + args[1:]) # need subprocess to spawn workers
|
| 59 |
+
except Exception as e:
|
| 60 |
+
print('Error:', e) # print to console
|
| 61 |
+
gr.Warning("Reconstruction failed, see console log for details.") # notify user
|
| 62 |
+
|
| 63 |
print('Finished inference at {}'.format(datetime.datetime.now()))
|
| 64 |
|
| 65 |
result_3d_model = out_file
|
|
|
|
| 66 |
|
| 67 |
+
return result_3d_model
|
| 68 |
|
| 69 |
|
| 70 |
def main():
|
| 71 |
+
description_header = '# PPSurf [Github](https://github.com/cg-tuwien/ppsurf) [Project](https://www.cg.tuwien.ac.at/research/publications/2024/erler_2024_ppsurf/)'
|
| 72 |
+
|
| 73 |
+
description_col0 = '''
|
| 74 |
Supported file formats:
|
| 75 |
- PLY, STL, OBJ and other mesh files,
|
| 76 |
- XYZ as whitespace-separated text file,
|
| 77 |
- NPY and NPZ (key='arr_0'),
|
| 78 |
- LAS and LAZ (version 1.0-1.4), COPC and CRS.
|
| 79 |
Best results for 50k-250k points.
|
| 80 |
+
'''
|
| 81 |
+
|
| 82 |
+
description_col1 = '''
|
| 83 |
This method is meant for scans of single and few objects.
|
| 84 |
Quality for scenes and landscapes will be lower.
|
| 85 |
|
| 86 |
+
Inference takes up to 180 seconds.
|
| 87 |
'''
|
| 88 |
|
| 89 |
# can't render many input types directly in Gradio Model3D
|
| 90 |
# so we need to convert to supported format
|
| 91 |
+
# Gradio can't draw point clouds anyway (2024-03-04), so we skip this for now
|
| 92 |
# def convert_to_ply(input_point_cloud_upload: gr.utils.NamedString):
|
| 93 |
#
|
| 94 |
# # add absolute path to import dirs
|
|
|
|
| 121 |
# # input_point_cloud_viewer.value = input_shape
|
| 122 |
|
| 123 |
if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
|
| 124 |
+
description_col1 += (f'\n<p>For faster inference without waiting in queue, '
|
| 125 |
+
f'you may duplicate the space and upgrade to GPU in settings. '
|
| 126 |
+
f'<a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true">'
|
| 127 |
+
f'<img style="display: inline; margin-top: 0em; margin-bottom: 0em" '
|
| 128 |
+
f'src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>')
|
| 129 |
|
| 130 |
with gr.Blocks(css='style.css') as demo:
|
| 131 |
+
gr.Markdown(description_header)
|
| 132 |
with gr.Row():
|
| 133 |
with gr.Column():
|
| 134 |
+
gr.Markdown(description_col0)
|
| 135 |
+
# with gr.Tabs() as input_tabs: # re-enable when Gradio supports point clouds
|
| 136 |
# with gr.TabItem(label='Input Point Cloud Upload', id='pc_upload'):
|
| 137 |
input_point_cloud_upload = gr.File(show_label=False, file_count='single')
|
| 138 |
# input_point_cloud_upload.upload(
|
|
|
|
| 158 |
label='Edge Refinement Iterations (larger for more details)',
|
| 159 |
minimum=3, maximum=30, value=10, step=1)
|
| 160 |
with gr.Column():
|
| 161 |
+
gr.Markdown(description_col1)
|
| 162 |
+
# progress_text = gr.Text(label='Progress')
|
| 163 |
+
with gr.Tabs():
|
| 164 |
+
with gr.TabItem(label='Reconstructed 3D model'):
|
| 165 |
+
result_3d_model = gr.Model3D(show_label=False)
|
| 166 |
# with gr.TabItem(label='Output mesh file'):
|
| 167 |
# output_file = gr.File(show_label=False)
|
| 168 |
# with gr.Row():
|
|
|
|
| 200 |
outputs=[
|
| 201 |
result_3d_model,
|
| 202 |
# output_file,
|
| 203 |
+
# progress_text,
|
| 204 |
])
|
| 205 |
|
| 206 |
demo.queue(max_size=5)
|