Spaces:
Running on Zero
Running on Zero
Bobby commited on
Commit ·
1ca14ed
1
Parent(s): 2ca094c
Save GLB/STL into repo exports directory and allow path
Browse files- .gitignore +1 -0
- app.py +7 -3
.gitignore
CHANGED
|
@@ -3,6 +3,7 @@ AGENTS.md
|
|
| 3 |
__pycache__/
|
| 4 |
*.pyc
|
| 5 |
cache/
|
|
|
|
| 6 |
tmp/
|
| 7 |
extensions/
|
| 8 |
wheels/
|
|
|
|
| 3 |
__pycache__/
|
| 4 |
*.pyc
|
| 5 |
cache/
|
| 6 |
+
exports/
|
| 7 |
tmp/
|
| 8 |
extensions/
|
| 9 |
wheels/
|
app.py
CHANGED
|
@@ -70,10 +70,13 @@ if TRELLIS_RUNTIME not in {"original", "trellis2"}:
|
|
| 70 |
|
| 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
|
|
@@ -227,6 +230,7 @@ def is_video_mostly_black(frames: List[np.ndarray], mean_threshold: float = 2.0)
|
|
| 227 |
def start_session(req: gr.Request):
|
| 228 |
clear_cuda_cache()
|
| 229 |
os.makedirs(TMP_DIR, exist_ok=True)
|
|
|
|
| 230 |
|
| 231 |
|
| 232 |
def end_session(req: gr.Request):
|
|
@@ -272,7 +276,7 @@ def export_stl_from_glb(glb_path: str) -> Optional[str]:
|
|
| 272 |
if current_size > 0:
|
| 273 |
mesh_to_export.vertices *= target_size_mm / current_size
|
| 274 |
current_time_stl = datetime.now().strftime("%Y-%m%d-%H%M%S-%f")
|
| 275 |
-
stl_path = os.path.join(
|
| 276 |
mesh_to_export.export(stl_path)
|
| 277 |
logger.info("STL exported: %s", stl_path)
|
| 278 |
|
|
@@ -701,7 +705,7 @@ def extract_model_from_state(
|
|
| 701 |
|
| 702 |
progress(0.75, desc="Exporting GLB...")
|
| 703 |
current_time_glb = datetime.now().strftime("%Y-%m%d-%H%M%S-%f")
|
| 704 |
-
glb_path = os.path.join(
|
| 705 |
glb.export(glb_path)
|
| 706 |
glb_path_abs = os.path.abspath(glb_path)
|
| 707 |
logger.info("GLB exported: %s (%d bytes)", glb_path_abs, os.path.getsize(glb_path_abs))
|
|
|
|
| 70 |
|
| 71 |
MAX_SEED = np.iinfo(np.int32).max
|
| 72 |
TMP_DIR = os.path.join("cache")
|
| 73 |
+
EXPORT_DIR = os.path.join("exports")
|
| 74 |
os.makedirs(TMP_DIR, exist_ok=True)
|
| 75 |
+
os.makedirs(EXPORT_DIR, exist_ok=True)
|
| 76 |
TMP_DIR_ABS = os.path.abspath(TMP_DIR)
|
| 77 |
+
EXPORT_DIR_ABS = os.path.abspath(EXPORT_DIR)
|
| 78 |
ASSETS_DIR_ABS = os.path.abspath("assets")
|
| 79 |
+
ALLOWED_PATHS = [TMP_DIR_ABS, EXPORT_DIR_ABS, ASSETS_DIR_ABS]
|
| 80 |
|
| 81 |
if gr.NO_RELOAD:
|
| 82 |
pipeline = None
|
|
|
|
| 230 |
def start_session(req: gr.Request):
|
| 231 |
clear_cuda_cache()
|
| 232 |
os.makedirs(TMP_DIR, exist_ok=True)
|
| 233 |
+
os.makedirs(EXPORT_DIR, exist_ok=True)
|
| 234 |
|
| 235 |
|
| 236 |
def end_session(req: gr.Request):
|
|
|
|
| 276 |
if current_size > 0:
|
| 277 |
mesh_to_export.vertices *= target_size_mm / current_size
|
| 278 |
current_time_stl = datetime.now().strftime("%Y-%m%d-%H%M%S-%f")
|
| 279 |
+
stl_path = os.path.join(EXPORT_DIR, f"{current_time_stl}.stl")
|
| 280 |
mesh_to_export.export(stl_path)
|
| 281 |
logger.info("STL exported: %s", stl_path)
|
| 282 |
|
|
|
|
| 705 |
|
| 706 |
progress(0.75, desc="Exporting GLB...")
|
| 707 |
current_time_glb = datetime.now().strftime("%Y-%m%d-%H%M%S-%f")
|
| 708 |
+
glb_path = os.path.join(EXPORT_DIR, f"{current_time_glb}.glb")
|
| 709 |
glb.export(glb_path)
|
| 710 |
glb_path_abs = os.path.abspath(glb_path)
|
| 711 |
logger.info("GLB exported: %s (%d bytes)", glb_path_abs, os.path.getsize(glb_path_abs))
|