Spaces:
Running
on
Zero
Running
on
Zero
demo
Browse files
app.py
CHANGED
|
@@ -16,6 +16,9 @@
|
|
| 16 |
"""
|
| 17 |
FaceLift: Single Image 3D Face Reconstruction
|
| 18 |
Generates 3D head models from single images using multi-view diffusion and GS-LRM.
|
|
|
|
|
|
|
|
|
|
| 19 |
"""
|
| 20 |
|
| 21 |
# Disable HF fast transfer if hf_transfer is not installed
|
|
@@ -62,7 +65,14 @@ def _log_viewer_file(ply_path: Path):
|
|
| 62 |
def upload_ply_to_hf(ply_path: Path, repo_id: str = "wlyu/FaceLift_demo") -> str:
|
| 63 |
"""Upload PLY file to HuggingFace and return the public URL."""
|
| 64 |
try:
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
ply_filename = ply_path.name
|
| 67 |
|
| 68 |
# Upload to tmp_ply folder
|
|
@@ -74,6 +84,7 @@ def upload_ply_to_hf(ply_path: Path, repo_id: str = "wlyu/FaceLift_demo") -> str
|
|
| 74 |
path_in_repo=path_in_repo,
|
| 75 |
repo_id=repo_id,
|
| 76 |
repo_type="model",
|
|
|
|
| 77 |
)
|
| 78 |
|
| 79 |
# Return the public URL
|
|
@@ -83,8 +94,8 @@ def upload_ply_to_hf(ply_path: Path, repo_id: str = "wlyu/FaceLift_demo") -> str
|
|
| 83 |
|
| 84 |
except Exception as e:
|
| 85 |
print(f"⚠️ Failed to upload to HuggingFace: {e}")
|
| 86 |
-
|
| 87 |
-
return
|
| 88 |
|
| 89 |
# -----------------------------
|
| 90 |
# Ensure diff-gaussian-rasterization builds for current GPU
|
|
@@ -371,29 +382,53 @@ class FaceLiftPipeline:
|
|
| 371 |
# Final CUDA cache clear
|
| 372 |
torch.cuda.empty_cache()
|
| 373 |
|
| 374 |
-
# Create viewer HTML
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
|
| 398 |
return (
|
| 399 |
str(output_path), # Reconstruction grid
|
|
|
|
| 16 |
"""
|
| 17 |
FaceLift: Single Image 3D Face Reconstruction
|
| 18 |
Generates 3D head models from single images using multi-view diffusion and GS-LRM.
|
| 19 |
+
|
| 20 |
+
Note: To enable the interactive 3D viewer, this Space needs write access to wlyu/FaceLift_demo.
|
| 21 |
+
Set the HF_TOKEN environment variable in Space settings with a token that has write access.
|
| 22 |
"""
|
| 23 |
|
| 24 |
# Disable HF fast transfer if hf_transfer is not installed
|
|
|
|
| 65 |
def upload_ply_to_hf(ply_path: Path, repo_id: str = "wlyu/FaceLift_demo") -> str:
|
| 66 |
"""Upload PLY file to HuggingFace and return the public URL."""
|
| 67 |
try:
|
| 68 |
+
# Get HF token from environment (automatically available in HF Spaces)
|
| 69 |
+
hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
| 70 |
+
|
| 71 |
+
if not hf_token:
|
| 72 |
+
print("⚠️ No HF_TOKEN found in environment, skipping upload")
|
| 73 |
+
return None
|
| 74 |
+
|
| 75 |
+
api = HfApi(token=hf_token)
|
| 76 |
ply_filename = ply_path.name
|
| 77 |
|
| 78 |
# Upload to tmp_ply folder
|
|
|
|
| 84 |
path_in_repo=path_in_repo,
|
| 85 |
repo_id=repo_id,
|
| 86 |
repo_type="model",
|
| 87 |
+
token=hf_token,
|
| 88 |
)
|
| 89 |
|
| 90 |
# Return the public URL
|
|
|
|
| 94 |
|
| 95 |
except Exception as e:
|
| 96 |
print(f"⚠️ Failed to upload to HuggingFace: {e}")
|
| 97 |
+
print(" Make sure the Space has write access to the repository")
|
| 98 |
+
return None
|
| 99 |
|
| 100 |
# -----------------------------
|
| 101 |
# Ensure diff-gaussian-rasterization builds for current GPU
|
|
|
|
| 382 |
# Final CUDA cache clear
|
| 383 |
torch.cuda.empty_cache()
|
| 384 |
|
| 385 |
+
# Create viewer HTML
|
| 386 |
+
if hf_ply_url:
|
| 387 |
+
# Successfully uploaded - show iframe viewer
|
| 388 |
+
viewer_url = f"https://www.wlyu.me/FaceLift/splat/index.html?url={hf_ply_url}"
|
| 389 |
+
|
| 390 |
+
viewer_html = f"""
|
| 391 |
+
<div style="width:100%; height:600px; position:relative; border-radius:8px; overflow:hidden; border:1px solid #333; background:#000;">
|
| 392 |
+
<iframe
|
| 393 |
+
src="{viewer_url}"
|
| 394 |
+
style="width:100%; height:100%; border:none;"
|
| 395 |
+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
| 396 |
+
allowfullscreen>
|
| 397 |
+
</iframe>
|
| 398 |
+
</div>
|
| 399 |
+
<div style="text-align:center; margin-top:10px; padding:10px;">
|
| 400 |
+
<a href="{viewer_url}"
|
| 401 |
+
target="_blank"
|
| 402 |
+
style="display:inline-block; color:#fff; background:#4CAF50; padding:10px 20px; text-decoration:none; font-size:14px; border-radius:6px; font-weight:500;">
|
| 403 |
+
🎮 Open Interactive Viewer in New Tab
|
| 404 |
+
</a>
|
| 405 |
+
<p style="color:#666; font-size:12px; margin-top:8px;">
|
| 406 |
+
Drag to rotate • Scroll to zoom • Right-click to pan
|
| 407 |
+
</p>
|
| 408 |
+
</div>
|
| 409 |
+
"""
|
| 410 |
+
else:
|
| 411 |
+
# Upload failed - provide instructions to use viewer manually
|
| 412 |
+
viewer_base_url = "https://www.wlyu.me/FaceLift/splat/index.html"
|
| 413 |
+
|
| 414 |
+
viewer_html = f"""
|
| 415 |
+
<div style="padding:40px; text-align:center; background:#f5f5f5; border-radius:8px; border:1px solid #ddd;">
|
| 416 |
+
<div style="font-size:48px; margin-bottom:20px;">🎮</div>
|
| 417 |
+
<h3 style="margin:0 0 15px 0; color:#333;">Interactive 3D Viewer</h3>
|
| 418 |
+
<p style="color:#666; margin-bottom:25px; line-height:1.6;">
|
| 419 |
+
Download the PLY file below, then drag and drop it into the viewer<br>
|
| 420 |
+
or use the viewer with a public URL
|
| 421 |
+
</p>
|
| 422 |
+
<a href="{viewer_base_url}"
|
| 423 |
+
target="_blank"
|
| 424 |
+
style="display:inline-block; color:#fff; background:#4CAF50; padding:12px 24px; text-decoration:none; font-size:15px; border-radius:6px; font-weight:500; margin-bottom:15px;">
|
| 425 |
+
🔗 Open Interactive Viewer
|
| 426 |
+
</a>
|
| 427 |
+
<p style="color:#888; font-size:13px; margin-top:15px;">
|
| 428 |
+
<strong>Controls:</strong> Drag to rotate • Scroll to zoom • Right-click to pan
|
| 429 |
+
</p>
|
| 430 |
+
</div>
|
| 431 |
+
"""
|
| 432 |
|
| 433 |
return (
|
| 434 |
str(output_path), # Reconstruction grid
|