Spaces:
Running on Zero
Running on Zero
Bobby commited on
Commit ·
2ca094c
1
Parent(s): 3af3570
Fix Spaces file serving and LitModel3D output path wiring
Browse files
app.py
CHANGED
|
@@ -71,6 +71,9 @@ if TRELLIS_RUNTIME not in {"original", "trellis2"}:
|
|
| 71 |
MAX_SEED = np.iinfo(np.int32).max
|
| 72 |
TMP_DIR = os.path.join("cache")
|
| 73 |
os.makedirs(TMP_DIR, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
if gr.NO_RELOAD:
|
| 76 |
pipeline = None
|
|
@@ -646,9 +649,9 @@ def extract_model_from_state(
|
|
| 646 |
texture_size: int,
|
| 647 |
req: gr.Request,
|
| 648 |
progress=gr.Progress(track_tqdm=True),
|
| 649 |
-
) -> Tuple[
|
| 650 |
if state is None:
|
| 651 |
-
return
|
| 652 |
|
| 653 |
if not torch.cuda.is_available():
|
| 654 |
raise gr.Error("GPU is not ready. Please retry in a few seconds.")
|
|
@@ -717,12 +720,16 @@ def extract_model_from_state(
|
|
| 717 |
|
| 718 |
stl_start = time.time()
|
| 719 |
stl_path = export_stl_from_glb(glb_path_abs)
|
|
|
|
|
|
|
| 720 |
logger.info("STL Export Time: %.2fs", time.time() - stl_start)
|
| 721 |
logger.info("Phase B Total Time: %.2fs", time.time() - job_start)
|
|
|
|
|
|
|
| 722 |
|
| 723 |
-
model_update = gr.update(value=glb_path_abs, visible=True)
|
| 724 |
stl_update = gr.update(value=stl_path, visible=True, interactive=bool(stl_path))
|
| 725 |
-
|
|
|
|
| 726 |
except RuntimeError as re:
|
| 727 |
if "out of memory" in str(re).lower():
|
| 728 |
clear_cuda_cache()
|
|
@@ -917,7 +924,7 @@ if __name__ == "__main__":
|
|
| 917 |
demo.queue(max_size=8, default_concurrency_limit=1, api_open=False).launch(
|
| 918 |
show_api=False,
|
| 919 |
share=False,
|
| 920 |
-
allowed_paths=
|
| 921 |
)
|
| 922 |
elif prod:
|
| 923 |
logger.info("Launching in PRODUCTION mode on port %s", port)
|
|
@@ -927,7 +934,7 @@ if __name__ == "__main__":
|
|
| 927 |
show_api=False,
|
| 928 |
favicon_path="assets/sb_3d_ai_logo.png",
|
| 929 |
share=False,
|
| 930 |
-
allowed_paths=
|
| 931 |
)
|
| 932 |
else:
|
| 933 |
logger.info("Launching in DEVELOPMENT mode on port %s", port)
|
|
@@ -938,5 +945,5 @@ if __name__ == "__main__":
|
|
| 938 |
favicon_path="assets/sb_3d_ai_logo.png",
|
| 939 |
debug=True,
|
| 940 |
share=True,
|
| 941 |
-
allowed_paths=
|
| 942 |
)
|
|
|
|
| 71 |
MAX_SEED = np.iinfo(np.int32).max
|
| 72 |
TMP_DIR = os.path.join("cache")
|
| 73 |
os.makedirs(TMP_DIR, exist_ok=True)
|
| 74 |
+
TMP_DIR_ABS = os.path.abspath(TMP_DIR)
|
| 75 |
+
ASSETS_DIR_ABS = os.path.abspath("assets")
|
| 76 |
+
ALLOWED_PATHS = [TMP_DIR_ABS, ASSETS_DIR_ABS]
|
| 77 |
|
| 78 |
if gr.NO_RELOAD:
|
| 79 |
pipeline = None
|
|
|
|
| 649 |
texture_size: int,
|
| 650 |
req: gr.Request,
|
| 651 |
progress=gr.Progress(track_tqdm=True),
|
| 652 |
+
) -> Tuple[Optional[str], Dict[str, Any]]:
|
| 653 |
if state is None:
|
| 654 |
+
return None, gr.update(value=None, visible=True, interactive=False)
|
| 655 |
|
| 656 |
if not torch.cuda.is_available():
|
| 657 |
raise gr.Error("GPU is not ready. Please retry in a few seconds.")
|
|
|
|
| 720 |
|
| 721 |
stl_start = time.time()
|
| 722 |
stl_path = export_stl_from_glb(glb_path_abs)
|
| 723 |
+
if stl_path is not None:
|
| 724 |
+
stl_path = os.path.abspath(stl_path)
|
| 725 |
logger.info("STL Export Time: %.2fs", time.time() - stl_start)
|
| 726 |
logger.info("Phase B Total Time: %.2fs", time.time() - job_start)
|
| 727 |
+
logger.info("Returning model file: %s", glb_path_abs)
|
| 728 |
+
logger.info("Returning STL file: %s", stl_path)
|
| 729 |
|
|
|
|
| 730 |
stl_update = gr.update(value=stl_path, visible=True, interactive=bool(stl_path))
|
| 731 |
+
# LitModel3D works most reliably when the output is the raw path string.
|
| 732 |
+
return glb_path_abs, stl_update
|
| 733 |
except RuntimeError as re:
|
| 734 |
if "out of memory" in str(re).lower():
|
| 735 |
clear_cuda_cache()
|
|
|
|
| 924 |
demo.queue(max_size=8, default_concurrency_limit=1, api_open=False).launch(
|
| 925 |
show_api=False,
|
| 926 |
share=False,
|
| 927 |
+
allowed_paths=ALLOWED_PATHS,
|
| 928 |
)
|
| 929 |
elif prod:
|
| 930 |
logger.info("Launching in PRODUCTION mode on port %s", port)
|
|
|
|
| 934 |
show_api=False,
|
| 935 |
favicon_path="assets/sb_3d_ai_logo.png",
|
| 936 |
share=False,
|
| 937 |
+
allowed_paths=ALLOWED_PATHS,
|
| 938 |
)
|
| 939 |
else:
|
| 940 |
logger.info("Launching in DEVELOPMENT mode on port %s", port)
|
|
|
|
| 945 |
favicon_path="assets/sb_3d_ai_logo.png",
|
| 946 |
debug=True,
|
| 947 |
share=True,
|
| 948 |
+
allowed_paths=ALLOWED_PATHS,
|
| 949 |
)
|