Spaces:
Running
on
Zero
Running
on
Zero
extract_glb modif (relative path)
Browse files
app.py
CHANGED
@@ -168,25 +168,18 @@ def extract_glb(
|
|
168 |
texture_size: int,
|
169 |
req: gr.Request,
|
170 |
) -> Tuple[str, str]:
|
171 |
-
"""
|
172 |
-
Extract a GLB file from the 3D model.
|
173 |
-
|
174 |
-
Args:
|
175 |
-
state (dict): The state of the generated 3D model.
|
176 |
-
mesh_simplify (float): The mesh simplification factor.
|
177 |
-
texture_size (int): The texture resolution.
|
178 |
-
|
179 |
-
Returns:
|
180 |
-
str: The path to the extracted GLB file.
|
181 |
-
"""
|
182 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
183 |
os.makedirs(user_dir, exist_ok=True)
|
184 |
gs, mesh = unpack_state(state)
|
185 |
glb = postprocessing_utils.to_glb(gs, mesh, simplify=mesh_simplify, texture_size=texture_size, verbose=False)
|
186 |
-
|
187 |
-
|
|
|
188 |
torch.cuda.empty_cache()
|
189 |
-
|
|
|
|
|
|
|
190 |
|
191 |
|
192 |
def prepare_multi_example() -> List[Image.Image]:
|
|
|
168 |
texture_size: int,
|
169 |
req: gr.Request,
|
170 |
) -> Tuple[str, str]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
172 |
os.makedirs(user_dir, exist_ok=True)
|
173 |
gs, mesh = unpack_state(state)
|
174 |
glb = postprocessing_utils.to_glb(gs, mesh, simplify=mesh_simplify, texture_size=texture_size, verbose=False)
|
175 |
+
# Save the GLB file to an absolute path
|
176 |
+
glb_path_absolute = os.path.join(user_dir, 'sample.glb')
|
177 |
+
glb.export(glb_path_absolute)
|
178 |
torch.cuda.empty_cache()
|
179 |
+
# Compute a relative path that Gradio can serve, e.g. "tmp/<session_hash>/sample.glb"
|
180 |
+
relative_path = os.path.join("tmp", str(req.session_hash), "sample.glb")
|
181 |
+
return relative_path, relative_path
|
182 |
+
|
183 |
|
184 |
|
185 |
def prepare_multi_example() -> List[Image.Image]:
|