Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -332,11 +332,53 @@ def move_to_device(model, device):
|
|
| 332 |
|
| 333 |
@spaces.GPU
|
| 334 |
def extract_glb(state: dict, mesh_simplify: float, texture_size: int) -> Tuple[str, str]:
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
|
| 341 |
|
| 342 |
def activate_button() -> gr.Button:
|
|
|
|
| 332 |
|
| 333 |
@spaces.GPU
|
| 334 |
def extract_glb(state: dict, mesh_simplify: float, texture_size: int) -> Tuple[str, str]:
|
| 335 |
+
try:
|
| 336 |
+
# GPU λ©λͺ¨λ¦¬ μ 리
|
| 337 |
+
clear_gpu_memory()
|
| 338 |
+
|
| 339 |
+
# μν μΈν¨νΉ
|
| 340 |
+
gs, mesh, trial_id = unpack_state(state)
|
| 341 |
+
|
| 342 |
+
# GLB λ³ν μ μ ν¨μ± κ²μ¬
|
| 343 |
+
if gs is None or mesh is None:
|
| 344 |
+
print("Error: Invalid gaussian or mesh data")
|
| 345 |
+
return None, None
|
| 346 |
+
|
| 347 |
+
# GLB λ³ν
|
| 348 |
+
with torch.inference_mode():
|
| 349 |
+
glb = postprocessing_utils.to_glb(
|
| 350 |
+
gs,
|
| 351 |
+
mesh,
|
| 352 |
+
simplify=mesh_simplify,
|
| 353 |
+
texture_size=texture_size,
|
| 354 |
+
verbose=True # λλ²κΉ
μ μν΄ verbose λͺ¨λ νμ±ν
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
if glb is None:
|
| 358 |
+
print("Error: GLB conversion failed")
|
| 359 |
+
return None, None
|
| 360 |
+
|
| 361 |
+
# νμΌ μ μ₯
|
| 362 |
+
glb_path = f"{TMP_DIR}/{trial_id}.glb"
|
| 363 |
+
try:
|
| 364 |
+
glb.export(glb_path)
|
| 365 |
+
if not os.path.exists(glb_path):
|
| 366 |
+
print(f"Error: GLB file was not created at {glb_path}")
|
| 367 |
+
return None, None
|
| 368 |
+
except Exception as e:
|
| 369 |
+
print(f"Error saving GLB file: {str(e)}")
|
| 370 |
+
return None, None
|
| 371 |
+
|
| 372 |
+
print(f"Successfully created GLB file at: {glb_path}")
|
| 373 |
+
return glb_path, glb_path
|
| 374 |
+
|
| 375 |
+
except Exception as e:
|
| 376 |
+
print(f"Error in extract_glb: {str(e)}")
|
| 377 |
+
return None, None
|
| 378 |
+
|
| 379 |
+
finally:
|
| 380 |
+
# μ 리 μμ
|
| 381 |
+
clear_gpu_memory()
|
| 382 |
|
| 383 |
|
| 384 |
def activate_button() -> gr.Button:
|