Spaces:
Running
on
Zero
Running
on
Zero
Update demo
Browse files
app.py
CHANGED
|
@@ -420,8 +420,21 @@ def main():
|
|
| 420 |
if not ply_path or not os.path.exists(ply_path):
|
| 421 |
return ""
|
| 422 |
return copy_to_session_and_get_url(ply_path, session_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
|
| 424 |
gr.Markdown("## FaceLift: Single Image 3D Face Reconstruction\nTurn a single portrait image into a 3D head model and preview it interactively.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
with gr.Row():
|
| 426 |
with gr.Column(scale=1):
|
| 427 |
in_image = gr.Image(type="filepath", label="Input Portrait Image")
|
|
@@ -440,26 +453,23 @@ def main():
|
|
| 440 |
)
|
| 441 |
|
| 442 |
with gr.Column(scale=1):
|
| 443 |
-
|
| 444 |
-
|
|
|
|
|
|
|
|
|
|
| 445 |
out_recon = gr.Image(label="3D Reconstruction")
|
| 446 |
out_video = gr.PlayableVideo(label="Turntable Animation")
|
| 447 |
-
out_ply = gr.File(label="3D
|
| 448 |
-
|
| 449 |
-
gr.Markdown("### Interactive Gaussian Splat Viewer")
|
| 450 |
-
with gr.Row():
|
| 451 |
-
url_box = gr.Textbox(label="Scene URL (auto-filled)", interactive=False)
|
| 452 |
-
viewer = gr.HTML("<div id='splat-container' style='width:100%;height:640px'></div>")
|
| 453 |
-
reload_btn = gr.Button("Reload Viewer")
|
| 454 |
|
| 455 |
# Initialize per-browser session
|
| 456 |
demo.load(fn=_init_session, inputs=None, outputs=session)
|
| 457 |
|
| 458 |
# Chain: run β show outputs β prepare viewer URL β load viewer (JS)
|
| 459 |
run_btn.click(
|
| 460 |
-
fn=
|
| 461 |
inputs=[in_image, auto_crop, guidance, seed, steps],
|
| 462 |
-
outputs=[
|
| 463 |
).then(
|
| 464 |
fn=_prep_viewer_url,
|
| 465 |
inputs=[out_ply, session],
|
|
|
|
| 420 |
if not ply_path or not os.path.exists(ply_path):
|
| 421 |
return ""
|
| 422 |
return copy_to_session_and_get_url(ply_path, session_id)
|
| 423 |
+
|
| 424 |
+
# Wrapper to return only the outputs we want to display
|
| 425 |
+
def _generate_and_filter_outputs(image_path, auto_crop, guidance_scale, random_seed, num_steps):
|
| 426 |
+
input_path, multiview_path, output_path, turntable_path, ply_path = \
|
| 427 |
+
pipeline.generate_3d_head(image_path, auto_crop, guidance_scale, random_seed, num_steps)
|
| 428 |
+
return output_path, turntable_path, ply_path
|
| 429 |
|
| 430 |
gr.Markdown("## FaceLift: Single Image 3D Face Reconstruction\nTurn a single portrait image into a 3D head model and preview it interactively.")
|
| 431 |
+
|
| 432 |
+
gr.Markdown("""
|
| 433 |
+
### π‘ Tips for Best Results
|
| 434 |
+
- **Works best with near-frontal portrait images**
|
| 435 |
+
- **Note:** These checkpoints were not trained with accessories (glasses, hats, etc.). Portraits containing accessories may produce suboptimal results.
|
| 436 |
+
""")
|
| 437 |
+
|
| 438 |
with gr.Row():
|
| 439 |
with gr.Column(scale=1):
|
| 440 |
in_image = gr.Image(type="filepath", label="Input Portrait Image")
|
|
|
|
| 453 |
)
|
| 454 |
|
| 455 |
with gr.Column(scale=1):
|
| 456 |
+
gr.Markdown("### Interactive Gaussian Splat Viewer")
|
| 457 |
+
viewer = gr.HTML("<div id='splat-container' style='width:100%;height:600px;background:#000;border:1px solid #ccc;border-radius:8px;'></div>")
|
| 458 |
+
url_box = gr.Textbox(label="Scene URL (auto-filled)", interactive=False, visible=False)
|
| 459 |
+
reload_btn = gr.Button("Reload Viewer", size="sm")
|
| 460 |
+
|
| 461 |
out_recon = gr.Image(label="3D Reconstruction")
|
| 462 |
out_video = gr.PlayableVideo(label="Turntable Animation")
|
| 463 |
+
out_ply = gr.File(label="3D Gaussians (.ply)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
|
| 465 |
# Initialize per-browser session
|
| 466 |
demo.load(fn=_init_session, inputs=None, outputs=session)
|
| 467 |
|
| 468 |
# Chain: run β show outputs β prepare viewer URL β load viewer (JS)
|
| 469 |
run_btn.click(
|
| 470 |
+
fn=_generate_and_filter_outputs,
|
| 471 |
inputs=[in_image, auto_crop, guidance, seed, steps],
|
| 472 |
+
outputs=[out_recon, out_video, out_ply],
|
| 473 |
).then(
|
| 474 |
fn=_prep_viewer_url,
|
| 475 |
inputs=[out_ply, session],
|