Spaces:
Runtime error
Runtime error
Upload gradio_app.py
Browse files- gradio_app.py +12 -39
gradio_app.py
CHANGED
@@ -123,10 +123,13 @@ def build_model_viewer_html(save_folder, height=660, width=790, textured=False):
|
|
123 |
related_path = f"./textured_mesh.glb"
|
124 |
template_name = './assets/modelviewer-textured-template.html'
|
125 |
output_html_path = os.path.join(save_folder, f'textured_mesh.html')
|
|
|
126 |
else:
|
127 |
related_path = f"./white_mesh.glb"
|
128 |
template_name = './assets/modelviewer-template.html'
|
129 |
output_html_path = os.path.join(save_folder, f'white_mesh.html')
|
|
|
|
|
130 |
offset = 50 if textured else 10
|
131 |
with open(os.path.join(CURRENT_DIR, template_name), 'r', encoding='utf-8') as f:
|
132 |
template_html = f.read()
|
@@ -134,39 +137,19 @@ def build_model_viewer_html(save_folder, height=660, width=790, textured=False):
|
|
134 |
with open(output_html_path, 'w', encoding='utf-8') as f:
|
135 |
template_html = template_html.replace('#height#', f'{height - offset}')
|
136 |
template_html = template_html.replace('#width#', f'{width}')
|
137 |
-
template_html = template_html.replace('#src#', f'{related_path}/')
|
|
|
138 |
f.write(template_html)
|
139 |
|
140 |
-
|
141 |
-
#print(
|
142 |
-
# f'Find html file {output_html_path}, {os.path.exists(output_html_path)}')
|
143 |
-
|
144 |
-
#return f"""
|
145 |
-
# <div style='height: {height}; width: 100%;'>
|
146 |
-
# {iframe_tag}
|
147 |
-
# </div>
|
148 |
-
#"""
|
149 |
-
|
150 |
-
|
151 |
-
if textured:
|
152 |
-
mesh_file_path = os.path.join(save_folder, f'textured_mesh.glb')
|
153 |
-
else:
|
154 |
-
mesh_file_path = os.path.join(save_folder, f'white_mesh.glb')
|
155 |
-
|
156 |
-
print(
|
157 |
-
f'Find html file {mesh_file_path}, {os.path.exists(mesh_file_path)}')
|
158 |
|
159 |
-
html
|
160 |
-
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
|
161 |
-
<model-viewer src="https://modelviewer.dev/shared-assets/models/Astronaut.glb"
|
162 |
-
alt="A 3D model of an astronaut"
|
163 |
-
auto-rotate
|
164 |
-
camera-controls
|
165 |
-
style="height: 500px; width: 500px;">
|
166 |
-
</model-viewer>
|
167 |
-
"""
|
168 |
|
169 |
-
return
|
|
|
|
|
|
|
|
|
170 |
|
171 |
@spaces.GPU(duration=40)
|
172 |
def _gen_shape(
|
@@ -496,16 +479,6 @@ def build_app():
|
|
496 |
with gr.Column(scale=9):
|
497 |
with gr.Tabs(selected='gen_mesh_panel') as tabs_output:
|
498 |
with gr.Tab('Generated Mesh', id='gen_mesh_panel'):
|
499 |
-
html_model_viewer="""
|
500 |
-
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
|
501 |
-
<model-viewer src="https://modelviewer.dev/shared-assets/models/Astronaut.glb"
|
502 |
-
alt="A 3D model of an astronaut"
|
503 |
-
auto-rotate
|
504 |
-
camera-controls
|
505 |
-
style="height: 500px; width: 500px;">
|
506 |
-
</model-viewer>
|
507 |
-
"""
|
508 |
-
gr.HTML(html_model_viewer)
|
509 |
html_gen_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
510 |
with gr.Tab('Exporting Mesh', id='export_mesh_panel'):
|
511 |
html_export_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
|
|
123 |
related_path = f"./textured_mesh.glb"
|
124 |
template_name = './assets/modelviewer-textured-template.html'
|
125 |
output_html_path = os.path.join(save_folder, f'textured_mesh.html')
|
126 |
+
mesh_file_path = os.path.join(save_folder, f'textured_mesh.glb')
|
127 |
else:
|
128 |
related_path = f"./white_mesh.glb"
|
129 |
template_name = './assets/modelviewer-template.html'
|
130 |
output_html_path = os.path.join(save_folder, f'white_mesh.html')
|
131 |
+
mesh_file_path = os.path.join(save_folder, f'white_mesh.glb')
|
132 |
+
|
133 |
offset = 50 if textured else 10
|
134 |
with open(os.path.join(CURRENT_DIR, template_name), 'r', encoding='utf-8') as f:
|
135 |
template_html = f.read()
|
|
|
137 |
with open(output_html_path, 'w', encoding='utf-8') as f:
|
138 |
template_html = template_html.replace('#height#', f'{height - offset}')
|
139 |
template_html = template_html.replace('#width#', f'{width}')
|
140 |
+
#template_html = template_html.replace('#src#', f'{related_path}/')
|
141 |
+
template_html = template_html.replace('#src#', f'{mesh_file_path}/')
|
142 |
f.write(template_html)
|
143 |
|
144 |
+
iframe_tag = f'<iframe src="file={output_html_path}" height="{height}" width="100%" frameborder="0"></iframe>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
+
print(f'Find html file {output_html_path}, {os.path.exists(output_html_path)}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
+
return f"""
|
149 |
+
<div style='height: {height}; width: 100%;'>
|
150 |
+
{iframe_tag}
|
151 |
+
</div>
|
152 |
+
"""
|
153 |
|
154 |
@spaces.GPU(duration=40)
|
155 |
def _gen_shape(
|
|
|
479 |
with gr.Column(scale=9):
|
480 |
with gr.Tabs(selected='gen_mesh_panel') as tabs_output:
|
481 |
with gr.Tab('Generated Mesh', id='gen_mesh_panel'):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
482 |
html_gen_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
483 |
with gr.Tab('Exporting Mesh', id='export_mesh_panel'):
|
484 |
html_export_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|