Spaces:
Running
on
Zero
Running
on
Zero
demo
Browse files
app.py
CHANGED
|
@@ -39,7 +39,7 @@ import yaml
|
|
| 39 |
from easydict import EasyDict as edict
|
| 40 |
from einops import rearrange
|
| 41 |
from PIL import Image
|
| 42 |
-
from huggingface_hub import snapshot_download
|
| 43 |
import spaces
|
| 44 |
|
| 45 |
# Install diff-gaussian-rasterization at runtime (requires GPU)
|
|
@@ -59,6 +59,33 @@ def _log_viewer_file(ply_path: Path):
|
|
| 59 |
}
|
| 60 |
print("[VIEWER-RETURN]", json.dumps(info))
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
# -----------------------------
|
| 63 |
# Ensure diff-gaussian-rasterization builds for current GPU
|
| 64 |
# -----------------------------
|
|
@@ -338,26 +365,33 @@ class FaceLiftPipeline:
|
|
| 338 |
# Log the viewer file for quick debugging
|
| 339 |
_log_viewer_file(ply_path)
|
| 340 |
|
|
|
|
|
|
|
|
|
|
| 341 |
# Final CUDA cache clear
|
| 342 |
torch.cuda.empty_cache()
|
| 343 |
|
| 344 |
# Create viewer HTML with iframe pointing to external viewer
|
| 345 |
-
|
|
|
|
| 346 |
viewer_html = f"""
|
| 347 |
-
<div style="width:100%; height:600px; position:relative; border-radius:8px; overflow:hidden; border:1px solid #333;">
|
| 348 |
<iframe
|
| 349 |
-
src="
|
| 350 |
style="width:100%; height:100%; border:none;"
|
| 351 |
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
| 352 |
allowfullscreen>
|
| 353 |
</iframe>
|
| 354 |
</div>
|
| 355 |
-
<div style="text-align:center; margin-top:10px;">
|
| 356 |
-
<a href="
|
| 357 |
target="_blank"
|
| 358 |
-
style="color:#4CAF50; text-decoration:none; font-size:
|
| 359 |
-
|
| 360 |
</a>
|
|
|
|
|
|
|
|
|
|
| 361 |
</div>
|
| 362 |
"""
|
| 363 |
|
|
|
|
| 39 |
from easydict import EasyDict as edict
|
| 40 |
from einops import rearrange
|
| 41 |
from PIL import Image
|
| 42 |
+
from huggingface_hub import snapshot_download, HfApi
|
| 43 |
import spaces
|
| 44 |
|
| 45 |
# Install diff-gaussian-rasterization at runtime (requires GPU)
|
|
|
|
| 59 |
}
|
| 60 |
print("[VIEWER-RETURN]", json.dumps(info))
|
| 61 |
|
| 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 |
+
api = HfApi()
|
| 66 |
+
ply_filename = ply_path.name
|
| 67 |
+
|
| 68 |
+
# Upload to tmp_ply folder
|
| 69 |
+
path_in_repo = f"tmp_ply/{ply_filename}"
|
| 70 |
+
|
| 71 |
+
print(f"Uploading {ply_filename} to HuggingFace...")
|
| 72 |
+
api.upload_file(
|
| 73 |
+
path_or_fileobj=str(ply_path),
|
| 74 |
+
path_in_repo=path_in_repo,
|
| 75 |
+
repo_id=repo_id,
|
| 76 |
+
repo_type="model",
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
# Return the public URL
|
| 80 |
+
hf_url = f"https://huggingface.co/{repo_id}/resolve/main/{path_in_repo}"
|
| 81 |
+
print(f"✓ Uploaded to: {hf_url}")
|
| 82 |
+
return hf_url
|
| 83 |
+
|
| 84 |
+
except Exception as e:
|
| 85 |
+
print(f"⚠️ Failed to upload to HuggingFace: {e}")
|
| 86 |
+
# Fallback to local path
|
| 87 |
+
return f"/file={ply_path}"
|
| 88 |
+
|
| 89 |
# -----------------------------
|
| 90 |
# Ensure diff-gaussian-rasterization builds for current GPU
|
| 91 |
# -----------------------------
|
|
|
|
| 365 |
# Log the viewer file for quick debugging
|
| 366 |
_log_viewer_file(ply_path)
|
| 367 |
|
| 368 |
+
# Upload PLY to HuggingFace for public access
|
| 369 |
+
hf_ply_url = upload_ply_to_hf(ply_path)
|
| 370 |
+
|
| 371 |
# Final CUDA cache clear
|
| 372 |
torch.cuda.empty_cache()
|
| 373 |
|
| 374 |
# Create viewer HTML with iframe pointing to external viewer
|
| 375 |
+
viewer_url = f"https://www.wlyu.me/FaceLift/splat/index.html?url={hf_ply_url}"
|
| 376 |
+
|
| 377 |
viewer_html = f"""
|
| 378 |
+
<div style="width:100%; height:600px; position:relative; border-radius:8px; overflow:hidden; border:1px solid #333; background:#000;">
|
| 379 |
<iframe
|
| 380 |
+
src="{viewer_url}"
|
| 381 |
style="width:100%; height:100%; border:none;"
|
| 382 |
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
| 383 |
allowfullscreen>
|
| 384 |
</iframe>
|
| 385 |
</div>
|
| 386 |
+
<div style="text-align:center; margin-top:10px; padding:10px;">
|
| 387 |
+
<a href="{viewer_url}"
|
| 388 |
target="_blank"
|
| 389 |
+
style="display:inline-block; color:#fff; background:#4CAF50; padding:10px 20px; text-decoration:none; font-size:14px; border-radius:6px; font-weight:500;">
|
| 390 |
+
🎮 Open Interactive Viewer in New Tab
|
| 391 |
</a>
|
| 392 |
+
<p style="color:#666; font-size:12px; margin-top:8px;">
|
| 393 |
+
Drag to rotate • Scroll to zoom • Right-click to pan
|
| 394 |
+
</p>
|
| 395 |
</div>
|
| 396 |
"""
|
| 397 |
|