Spaces:
Running
on
L4
Running
on
L4
Undo zerogpu stuff
Browse files- gradio_app.py +34 -42
gradio_app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
-
|
|
|
3 |
|
4 |
import random
|
5 |
import tempfile
|
@@ -17,55 +18,48 @@ from gradio_pointcloudeditor import PointCloudEditor
|
|
17 |
from PIL import Image
|
18 |
from transparent_background import Remover
|
19 |
|
|
|
|
|
|
|
20 |
|
21 |
-
|
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 |
-
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
|
48 |
-
|
49 |
|
50 |
-
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
-
|
61 |
-
|
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,7 +332,6 @@ def regenerate_run(
|
|
338 |
)
|
339 |
|
340 |
|
341 |
-
@spaces.GPU
|
342 |
def run_button(
|
343 |
run_btn,
|
344 |
input_image,
|
@@ -355,7 +348,6 @@ def run_button(
|
|
355 |
texture_resolution,
|
356 |
):
|
357 |
if run_btn == "Run":
|
358 |
-
|
359 |
if torch.cuda.is_available():
|
360 |
torch.cuda.reset_peak_memory_stats()
|
361 |
|
|
|
1 |
import os
|
2 |
+
|
3 |
+
os.system("pip install ./texture_baker/ ./uv_unwrapper/")
|
4 |
|
5 |
import random
|
6 |
import tempfile
|
|
|
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 |
+
os.environ["GRADIO_TEMP_DIR"] = os.path.join(os.environ.get("TMPDIR", "/tmp"), "gradio")
|
|
|
|
|
|
|
|
|
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 |
|
65 |
def forward_model(
|
|
|
332 |
)
|
333 |
|
334 |
|
|
|
335 |
def run_button(
|
336 |
run_btn,
|
337 |
input_image,
|
|
|
348 |
texture_resolution,
|
349 |
):
|
350 |
if run_btn == "Run":
|
|
|
351 |
if torch.cuda.is_available():
|
352 |
torch.cuda.reset_peak_memory_stats()
|
353 |
|