Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
# MIT License
|
| 2 |
-
#
|
| 3 |
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
-
# of this software and associated documentation files (the "Software"), to deal
|
| 5 |
-
# in the Software without restriction, including without limitation the rights
|
| 6 |
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 7 |
-
# copies of the Software, and to permit persons to do so, subject to the following conditions:
|
| 8 |
-
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 9 |
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 10 |
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 11 |
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 12 |
-
|
| 13 |
-
# Copyright (c) [2025] [Microsoft]
|
| 14 |
-
# Copyright (c) [2025] [Chongjie Ye]
|
| 15 |
-
# SPDX-License-Identifier: MIT
|
| 16 |
-
# This file has been modified by Chongjie Ye on 2025/04/10
|
| 17 |
-
# Original file was released under MIT, with the full license text available at:
|
| 18 |
-
# https://github.com/atong01/conditional-flow-matching/blob/1.0.7/LICENSE
|
| 19 |
-
# This modified file is released under the same license.
|
| 20 |
|
| 21 |
import gradio as gr
|
| 22 |
import os
|
|
@@ -86,6 +69,7 @@ import trimesh
|
|
| 86 |
|
| 87 |
# ---- Force CPU inside hi3dgen (avoid any CUDA paths) ----
|
| 88 |
print("[PATCH] Applying CPU monkey-patches to hi3dgen")
|
|
|
|
| 89 |
# 1) utils_cube.construct_dense_grid(..., device=...) -> force CPU
|
| 90 |
uc = importlib.import_module("hi3dgen.representations.mesh.utils_cube")
|
| 91 |
if not hasattr(uc, "_CPU_PATCHED"):
|
|
@@ -96,16 +80,21 @@ if not hasattr(uc, "_CPU_PATCHED"):
|
|
| 96 |
uc._CPU_PATCHED = True
|
| 97 |
print("[PATCH] utils_cube.construct_dense_grid -> CPU")
|
| 98 |
|
| 99 |
-
# 2) cube2mesh.EnhancedMarchingCubes default device -> force CPU
|
| 100 |
cm = importlib.import_module("hi3dgen.representations.mesh.cube2mesh")
|
| 101 |
M = cm.EnhancedMarchingCubes
|
| 102 |
if not hasattr(M, "_CPU_PATCHED"):
|
| 103 |
_orig_init = M.__init__
|
| 104 |
-
def _init_cpu(self,
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
M.__init__ = _init_cpu
|
| 107 |
M._CPU_PATCHED = True
|
| 108 |
-
print("[PATCH] cube2mesh.EnhancedMarchingCubes.__init__ -> CPU")
|
| 109 |
|
| 110 |
# 3) Belt & suspenders: coerce torch.arange(device='cuda') to CPU if any call slips through
|
| 111 |
if not hasattr(torch, "_ARANGE_CPU_PATCHED"):
|
|
@@ -337,8 +326,8 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
| 337 |
gr.Markdown(
|
| 338 |
"""
|
| 339 |
**Acknowledgments**: Hi3DGen is built on the shoulders of giants. We would like to express our gratitude to the open-source research community and the developers of these pioneering projects:
|
| 340 |
-
- **3D Modeling:** Our 3D Model is finetuned from the SOTA open-source 3D foundation model [Trellis](https://github.com/microsoft/TRELLIS); inspired by
|
| 341 |
-
- **Normal Estimation:** Builds on
|
| 342 |
"""
|
| 343 |
)
|
| 344 |
|
|
@@ -374,7 +363,6 @@ if __name__ == "__main__":
|
|
| 374 |
yoso_version='yoso-normal-v1-8-1',
|
| 375 |
local_cache_dir='./weights'
|
| 376 |
)
|
| 377 |
-
|
| 378 |
try:
|
| 379 |
normal_predictor.to("cpu")
|
| 380 |
except Exception:
|
|
|
|
| 1 |
# MIT License
|
| 2 |
+
# (see original notice and terms)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import os
|
|
|
|
| 69 |
|
| 70 |
# ---- Force CPU inside hi3dgen (avoid any CUDA paths) ----
|
| 71 |
print("[PATCH] Applying CPU monkey-patches to hi3dgen")
|
| 72 |
+
|
| 73 |
# 1) utils_cube.construct_dense_grid(..., device=...) -> force CPU
|
| 74 |
uc = importlib.import_module("hi3dgen.representations.mesh.utils_cube")
|
| 75 |
if not hasattr(uc, "_CPU_PATCHED"):
|
|
|
|
| 80 |
uc._CPU_PATCHED = True
|
| 81 |
print("[PATCH] utils_cube.construct_dense_grid -> CPU")
|
| 82 |
|
| 83 |
+
# 2) cube2mesh.EnhancedMarchingCubes default device -> force CPU (flexible)
|
| 84 |
cm = importlib.import_module("hi3dgen.representations.mesh.cube2mesh")
|
| 85 |
M = cm.EnhancedMarchingCubes
|
| 86 |
if not hasattr(M, "_CPU_PATCHED"):
|
| 87 |
_orig_init = M.__init__
|
| 88 |
+
def _init_cpu(self, *args, **kwargs):
|
| 89 |
+
# Ensure device is CPU regardless of how it's passed
|
| 90 |
+
if "device" in kwargs:
|
| 91 |
+
kwargs["device"] = torch.device("cpu")
|
| 92 |
+
else:
|
| 93 |
+
kwargs.setdefault("device", torch.device("cpu"))
|
| 94 |
+
return _orig_init(self, *args, **kwargs)
|
| 95 |
M.__init__ = _init_cpu
|
| 96 |
M._CPU_PATCHED = True
|
| 97 |
+
print("[PATCH] cube2mesh.EnhancedMarchingCubes.__init__ -> CPU (flex)")
|
| 98 |
|
| 99 |
# 3) Belt & suspenders: coerce torch.arange(device='cuda') to CPU if any call slips through
|
| 100 |
if not hasattr(torch, "_ARANGE_CPU_PATCHED"):
|
|
|
|
| 326 |
gr.Markdown(
|
| 327 |
"""
|
| 328 |
**Acknowledgments**: Hi3DGen is built on the shoulders of giants. We would like to express our gratitude to the open-source research community and the developers of these pioneering projects:
|
| 329 |
+
- **3D Modeling:** Our 3D Model is finetuned from the SOTA open-source 3D foundation model [Trellis](https://github.com/microsoft/TRELLIS); inspired by Rodin, Tripo, and Dora.
|
| 330 |
+
- **Normal Estimation:** Builds on StableNormal and GenPercept.
|
| 331 |
"""
|
| 332 |
)
|
| 333 |
|
|
|
|
| 363 |
yoso_version='yoso-normal-v1-8-1',
|
| 364 |
local_cache_dir='./weights'
|
| 365 |
)
|
|
|
|
| 366 |
try:
|
| 367 |
normal_predictor.to("cpu")
|
| 368 |
except Exception:
|