Spaces:
Running
on
T4
Running
on
T4
Upload gradio_app.py
Browse files- gradio_app.py +22 -9
gradio_app.py
CHANGED
@@ -142,14 +142,7 @@ def build_model_viewer_html(save_folder, path, height=660, width=790, textured=F
|
|
142 |
template_html = template_html.replace('#src#', f'https://nicolasg2523-picsto3d.hf.space/gradio_api/file=/tmp/{path}')
|
143 |
f.write(template_html)
|
144 |
|
145 |
-
|
146 |
-
iframe_tag = f'<iframe srcdoc="{tenplate_html_encoded}" height="{height}" width="100%" frameborder="0"></iframe>'
|
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(
|
@@ -484,6 +477,26 @@ def build_app():
|
|
484 |
with gr.Tabs(selected='gen_mesh_panel') as tabs_output:
|
485 |
with gr.Tab('Generated Mesh', id='gen_mesh_panel'):
|
486 |
html_gen_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
487 |
with gr.Tab('Exporting Mesh', id='export_mesh_panel'):
|
488 |
html_export_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
489 |
with gr.Tab('Mesh Statistic', id='stats_panel'):
|
@@ -507,7 +520,7 @@ def build_app():
|
|
507 |
num_chunks,
|
508 |
randomize_seed,
|
509 |
],
|
510 |
-
outputs=[file_out, html_gen_mesh, stats, seed]
|
511 |
).then(
|
512 |
lambda: (gr.update(visible=False, value=False), gr.update(interactive=True), gr.update(interactive=True),
|
513 |
gr.update(interactive=False)),
|
|
|
142 |
template_html = template_html.replace('#src#', f'https://nicolasg2523-picsto3d.hf.space/gradio_api/file=/tmp/{path}')
|
143 |
f.write(template_html)
|
144 |
|
145 |
+
return output_html_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
@spaces.GPU(duration=40)
|
148 |
def _gen_shape(
|
|
|
477 |
with gr.Tabs(selected='gen_mesh_panel') as tabs_output:
|
478 |
with gr.Tab('Generated Mesh', id='gen_mesh_panel'):
|
479 |
html_gen_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
480 |
+
file_output = gr.File(label="Generated GLB")
|
481 |
+
iframe_html = """
|
482 |
+
<iframe id="model_iframe" style="width:500px;height:500px;"></iframe>
|
483 |
+
<script>
|
484 |
+
function updateIframe(srcUrl) {
|
485 |
+
document.getElementById('model_iframe').srcdoc = `
|
486 |
+
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
|
487 |
+
<model-viewer src="${srcUrl}" camera-controls auto-rotate style="height:500px;width:500px;"></model-viewer>
|
488 |
+
`;
|
489 |
+
}
|
490 |
+
</script>
|
491 |
+
"""
|
492 |
+
iframe = gr.HTML(iframe_html)
|
493 |
+
file_output.change(fn=js_update, inputs=file_output, outputs=js_injection)
|
494 |
+
|
495 |
+
def js_update(file):
|
496 |
+
return f"<script>updateIframe('{file}');</script>"
|
497 |
+
|
498 |
+
js_injection = gr.HTML()
|
499 |
+
|
500 |
with gr.Tab('Exporting Mesh', id='export_mesh_panel'):
|
501 |
html_export_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
502 |
with gr.Tab('Mesh Statistic', id='stats_panel'):
|
|
|
520 |
num_chunks,
|
521 |
randomize_seed,
|
522 |
],
|
523 |
+
outputs=[file_out, html_gen_mesh, stats, seed, file_output]
|
524 |
).then(
|
525 |
lambda: (gr.update(visible=False, value=False), gr.update(interactive=True), gr.update(interactive=True),
|
526 |
gr.update(interactive=False)),
|