Fixes for ZeroGPU
Browse files- gradio_app.py +42 -34
- texture_baker/setup.py +3 -0
gradio_app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import os
|
2 |
-
|
3 |
-
os.system("pip install ./texture_baker/ ./uv_unwrapper/")
|
4 |
|
5 |
import random
|
6 |
import tempfile
|
@@ -18,48 +17,55 @@ from gradio_pointcloudeditor import PointCloudEditor
|
|
18 |
from PIL import Image
|
19 |
from transparent_background import Remover
|
20 |
|
21 |
-
import spar3d.utils as spar3d_utils
|
22 |
-
from spar3d.models.mesh import QUAD_REMESH_AVAILABLE, TRIANGLE_REMESH_AVAILABLE
|
23 |
-
from spar3d.system import SPAR3D
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
bg_remover = Remover() # default setting
|
28 |
|
29 |
-
COND_WIDTH = 512
|
30 |
-
COND_HEIGHT = 512
|
31 |
-
COND_DISTANCE = 2.2
|
32 |
-
COND_FOVY = 0.591627
|
33 |
-
BACKGROUND_COLOR = [0.5, 0.5, 0.5]
|
34 |
|
35 |
-
# Cached. Doesn't change
|
36 |
-
c2w_cond = spar3d_utils.default_cond_c2w(COND_DISTANCE)
|
37 |
-
intrinsic, intrinsic_normed_cond = spar3d_utils.create_intrinsic_from_fov_rad(
|
38 |
-
|
39 |
-
)
|
40 |
|
41 |
-
generated_files = []
|
42 |
|
43 |
-
# Delete previous gradio temp dir folder
|
44 |
-
if os.path.exists(os.environ["GRADIO_TEMP_DIR"]):
|
45 |
-
|
46 |
-
|
47 |
|
48 |
-
|
49 |
|
50 |
-
device = spar3d_utils.get_device()
|
51 |
|
52 |
-
model = SPAR3D.from_pretrained(
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
)
|
57 |
-
model.eval()
|
58 |
-
model = model.to(device)
|
59 |
|
60 |
-
example_files = [
|
61 |
-
|
62 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
|
65 |
def forward_model(
|
@@ -332,6 +338,7 @@ def regenerate_run(
|
|
332 |
)
|
333 |
|
334 |
|
|
|
335 |
def run_button(
|
336 |
run_btn,
|
337 |
input_image,
|
@@ -348,6 +355,7 @@ def run_button(
|
|
348 |
texture_resolution,
|
349 |
):
|
350 |
if run_btn == "Run":
|
|
|
351 |
if torch.cuda.is_available():
|
352 |
torch.cuda.reset_peak_memory_stats()
|
353 |
|
|
|
1 |
import os
|
2 |
+
import spaces
|
|
|
3 |
|
4 |
import random
|
5 |
import tempfile
|
|
|
17 |
from PIL import Image
|
18 |
from transparent_background import Remover
|
19 |
|
|
|
|
|
|
|
20 |
|
21 |
+
@spaces.GPU
|
22 |
+
def setup():
|
23 |
+
os.environ["GRADIO_TEMP_DIR"] = os.path.join(os.environ.get("TMPDIR", "/tmp"), "gradio")
|
24 |
+
|
25 |
+
os.system("USE_CUDA=1 pip install -vv ./texture_baker ./uv_unwrapper")
|
26 |
|
27 |
+
bg_remover = Remover() # default setting
|
28 |
|
29 |
+
COND_WIDTH = 512
|
30 |
+
COND_HEIGHT = 512
|
31 |
+
COND_DISTANCE = 2.2
|
32 |
+
COND_FOVY = 0.591627
|
33 |
+
BACKGROUND_COLOR = [0.5, 0.5, 0.5]
|
34 |
|
35 |
+
# Cached. Doesn't change
|
36 |
+
c2w_cond = spar3d_utils.default_cond_c2w(COND_DISTANCE)
|
37 |
+
intrinsic, intrinsic_normed_cond = spar3d_utils.create_intrinsic_from_fov_rad(
|
38 |
+
COND_FOVY, COND_HEIGHT, COND_WIDTH
|
39 |
+
)
|
40 |
|
41 |
+
generated_files = []
|
42 |
|
43 |
+
# Delete previous gradio temp dir folder
|
44 |
+
if os.path.exists(os.environ["GRADIO_TEMP_DIR"]):
|
45 |
+
print(f"Deleting {os.environ['GRADIO_TEMP_DIR']}")
|
46 |
+
import shutil
|
47 |
|
48 |
+
shutil.rmtree(os.environ["GRADIO_TEMP_DIR"])
|
49 |
|
50 |
+
device = spar3d_utils.get_device()
|
51 |
|
52 |
+
model = SPAR3D.from_pretrained(
|
53 |
+
"stabilityai/stable-point-aware-3d",
|
54 |
+
config_name="config.yaml",
|
55 |
+
weight_name="model.safetensors",
|
56 |
+
)
|
57 |
+
model.eval()
|
58 |
+
model = model.to(device)
|
59 |
|
60 |
+
example_files = [
|
61 |
+
os.path.join("demo_files/examples", f) for f in os.listdir("demo_files/examples")
|
62 |
+
]
|
63 |
+
|
64 |
+
setup()
|
65 |
+
|
66 |
+
import spar3d.utils as spar3d_utils
|
67 |
+
from spar3d.models.mesh import QUAD_REMESH_AVAILABLE, TRIANGLE_REMESH_AVAILABLE
|
68 |
+
from spar3d.system import SPAR3D
|
69 |
|
70 |
|
71 |
def forward_model(
|
|
|
338 |
)
|
339 |
|
340 |
|
341 |
+
@spaces.GPU
|
342 |
def run_button(
|
343 |
run_btn,
|
344 |
input_image,
|
|
|
355 |
texture_resolution,
|
356 |
):
|
357 |
if run_btn == "Run":
|
358 |
+
|
359 |
if torch.cuda.is_available():
|
360 |
torch.cuda.reset_peak_memory_stats()
|
361 |
|
texture_baker/setup.py
CHANGED
@@ -52,6 +52,9 @@ def get_extensions():
|
|
52 |
extra_compile_args["nvcc"].append("-g")
|
53 |
extra_link_args.extend(["-O0", "-g"])
|
54 |
|
|
|
|
|
|
|
55 |
define_macros = []
|
56 |
extensions = []
|
57 |
libraries = []
|
|
|
52 |
extra_compile_args["nvcc"].append("-g")
|
53 |
extra_link_args.extend(["-O0", "-g"])
|
54 |
|
55 |
+
if use_cuda:
|
56 |
+
extra_compile_args["nvcc"].append("--gpu-architecture=sm_80")
|
57 |
+
|
58 |
define_macros = []
|
59 |
extensions = []
|
60 |
libraries = []
|