Spaces:
Paused
Paused
Long Hoang
commited on
Commit
·
251bcd6
1
Parent(s):
3048b6a
feat: upload both PLY and GLB to HF Hub, fix video resize warning
Browse files- app.py +39 -17
- render_by_interp.py +1 -1
app.py
CHANGED
|
@@ -241,28 +241,50 @@ def process(inputfiles, input_path=None):
|
|
| 241 |
print("Video not found at:", output_video_path)
|
| 242 |
raise gr.Error(f"Video file not found at {output_video_path}")
|
| 243 |
|
| 244 |
-
# ------ (4) upload .ply to this Space repo & build URL ------
|
| 245 |
-
ply_url = None
|
| 246 |
-
rel_remote_path = f"outputs/{tmp_user_folder}_point_cloud.ply"
|
| 247 |
-
try:
|
| 248 |
-
api = HfApi()
|
| 249 |
-
api.upload_file(
|
| 250 |
-
repo_id=SPACE_REPO_ID,
|
| 251 |
-
repo_type="space",
|
| 252 |
-
path_or_fileobj=output_ply_path,
|
| 253 |
-
path_in_repo=rel_remote_path,
|
| 254 |
-
)
|
| 255 |
-
ply_url = f"https://huggingface.co/spaces/{SPACE_REPO_ID}/resolve/main/{rel_remote_path}"
|
| 256 |
-
print("Uploaded PLY to:", ply_url)
|
| 257 |
-
except Exception as e:
|
| 258 |
-
print("Failed to upload PLY to hub:", e)
|
| 259 |
-
ply_url = f"LOCAL:{output_ply_path}"
|
| 260 |
-
|
| 261 |
# Convert PLY to GLB for visualization
|
| 262 |
output_glb_path = output_ply_path.replace('.ply', '.glb')
|
| 263 |
if not convert_ply_to_glb(output_ply_path, output_glb_path):
|
| 264 |
output_glb_path = None
|
| 265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
# return:
|
| 267 |
# 1) video path (for gr.Video)
|
| 268 |
# 2) ply URL (for API + textbox)
|
|
|
|
| 241 |
print("Video not found at:", output_video_path)
|
| 242 |
raise gr.Error(f"Video file not found at {output_video_path}")
|
| 243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
# Convert PLY to GLB for visualization
|
| 245 |
output_glb_path = output_ply_path.replace('.ply', '.glb')
|
| 246 |
if not convert_ply_to_glb(output_ply_path, output_glb_path):
|
| 247 |
output_glb_path = None
|
| 248 |
|
| 249 |
+
# ------ (4) upload .ply and .glb to this Space repo & build URL ------
|
| 250 |
+
ply_url = None
|
| 251 |
+
glb_url = None
|
| 252 |
+
rel_remote_path_ply = f"outputs/{tmp_user_folder}_point_cloud.ply"
|
| 253 |
+
rel_remote_path_glb = f"outputs/{tmp_user_folder}_point_cloud.glb"
|
| 254 |
+
|
| 255 |
+
hf_token = os.environ.get("HF_TOKEN")
|
| 256 |
+
if hf_token:
|
| 257 |
+
try:
|
| 258 |
+
api = HfApi(token=hf_token)
|
| 259 |
+
|
| 260 |
+
# Upload PLY
|
| 261 |
+
api.upload_file(
|
| 262 |
+
repo_id=SPACE_REPO_ID,
|
| 263 |
+
repo_type="space",
|
| 264 |
+
path_or_fileobj=output_ply_path,
|
| 265 |
+
path_in_repo=rel_remote_path_ply,
|
| 266 |
+
)
|
| 267 |
+
ply_url = f"https://huggingface.co/spaces/{SPACE_REPO_ID}/resolve/main/{rel_remote_path_ply}"
|
| 268 |
+
print("Uploaded PLY to:", ply_url)
|
| 269 |
+
|
| 270 |
+
# Upload GLB if it exists
|
| 271 |
+
if output_glb_path and os.path.exists(output_glb_path):
|
| 272 |
+
api.upload_file(
|
| 273 |
+
repo_id=SPACE_REPO_ID,
|
| 274 |
+
repo_type="space",
|
| 275 |
+
path_or_fileobj=output_glb_path,
|
| 276 |
+
path_in_repo=rel_remote_path_glb,
|
| 277 |
+
)
|
| 278 |
+
glb_url = f"https://huggingface.co/spaces/{SPACE_REPO_ID}/resolve/main/{rel_remote_path_glb}"
|
| 279 |
+
print("Uploaded GLB to:", glb_url)
|
| 280 |
+
|
| 281 |
+
except Exception as e:
|
| 282 |
+
print("Failed to upload files to hub:", e)
|
| 283 |
+
ply_url = f"Error uploading: {e}"
|
| 284 |
+
else:
|
| 285 |
+
print("HF_TOKEN not found, skipping Hub upload.")
|
| 286 |
+
ply_url = "HF_TOKEN not set"
|
| 287 |
+
|
| 288 |
# return:
|
| 289 |
# 1) video path (for gr.Video)
|
| 290 |
# 2) ply URL (for API + textbox)
|
render_by_interp.py
CHANGED
|
@@ -68,7 +68,7 @@ def images_to_video(image_folder, output_video_path, fps=30):
|
|
| 68 |
image = imageio.imread(image_path)
|
| 69 |
images.append(image)
|
| 70 |
|
| 71 |
-
imageio.mimwrite(output_video_path, images, fps=fps)
|
| 72 |
|
| 73 |
|
| 74 |
def render_set(model_path, name, iteration, views, gaussians, pipeline, background):
|
|
|
|
| 68 |
image = imageio.imread(image_path)
|
| 69 |
images.append(image)
|
| 70 |
|
| 71 |
+
imageio.mimwrite(output_video_path, images, fps=fps, macro_block_size=1)
|
| 72 |
|
| 73 |
|
| 74 |
def render_set(model_path, name, iteration, views, gaussians, pipeline, background):
|