Spaces:
Running
on
Zero
Running
on
Zero
fix user dir errors from API
Browse files
app.py
CHANGED
@@ -105,7 +105,11 @@ def text_to_3d(
|
|
105 |
dict: The information of the generated 3D model.
|
106 |
str: The path to the video of the 3D model.
|
107 |
"""
|
108 |
-
user_dir
|
|
|
|
|
|
|
|
|
109 |
outputs = pipeline.run(
|
110 |
prompt,
|
111 |
seed=seed,
|
@@ -123,7 +127,13 @@ def text_to_3d(
|
|
123 |
video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
|
124 |
video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
|
125 |
video_path = os.path.join(user_dir, 'sample.mp4')
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
state = pack_state(outputs['gaussian'][0], outputs['mesh'][0])
|
128 |
torch.cuda.empty_cache()
|
129 |
return state, video_path
|
@@ -147,11 +157,19 @@ def extract_glb(
|
|
147 |
Returns:
|
148 |
str: The path to the extracted GLB file.
|
149 |
"""
|
150 |
-
user_dir
|
|
|
|
|
|
|
|
|
151 |
gs, mesh = unpack_state(state)
|
152 |
glb = postprocessing_utils.to_glb(gs, mesh, simplify=mesh_simplify, texture_size=texture_size, verbose=False)
|
153 |
glb_path = os.path.join(user_dir, 'sample.glb')
|
154 |
-
|
|
|
|
|
|
|
|
|
155 |
torch.cuda.empty_cache()
|
156 |
return glb_path, glb_path
|
157 |
|
@@ -167,10 +185,18 @@ def extract_gaussian(state: dict, req: gr.Request) -> Tuple[str, str]:
|
|
167 |
Returns:
|
168 |
str: The path to the extracted Gaussian file.
|
169 |
"""
|
170 |
-
user_dir
|
|
|
|
|
|
|
|
|
171 |
gs, _ = unpack_state(state)
|
172 |
gaussian_path = os.path.join(user_dir, 'sample.ply')
|
173 |
-
|
|
|
|
|
|
|
|
|
174 |
torch.cuda.empty_cache()
|
175 |
return gaussian_path, gaussian_path
|
176 |
|
|
|
105 |
dict: The information of the generated 3D model.
|
106 |
str: The path to the video of the 3D model.
|
107 |
"""
|
108 |
+
# --- Determine user_dir robustly ---
|
109 |
+
session_hash_str = str(req.session_hash) if hasattr(req, 'session_hash') and req.session_hash else f"api_call_{np.random.randint(10000)}"
|
110 |
+
user_dir = os.path.join(TMP_DIR, session_hash_str)
|
111 |
+
os.makedirs(user_dir, exist_ok=True) # Ensure directory exists
|
112 |
+
|
113 |
outputs = pipeline.run(
|
114 |
prompt,
|
115 |
seed=seed,
|
|
|
127 |
video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
|
128 |
video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
|
129 |
video_path = os.path.join(user_dir, 'sample.mp4')
|
130 |
+
try:
|
131 |
+
imageio.mimsave(video_path, video, fps=15) # Now the directory should exist
|
132 |
+
except FileNotFoundError:
|
133 |
+
print(f"ERROR: Directory {user_dir} still not found before mimsave!", file=sys.stderr)
|
134 |
+
# Decide if we should raise or return an error state?
|
135 |
+
# Returning a dummy path might hide the error, so let's raise for now
|
136 |
+
raise
|
137 |
state = pack_state(outputs['gaussian'][0], outputs['mesh'][0])
|
138 |
torch.cuda.empty_cache()
|
139 |
return state, video_path
|
|
|
157 |
Returns:
|
158 |
str: The path to the extracted GLB file.
|
159 |
"""
|
160 |
+
# --- Determine user_dir robustly ---
|
161 |
+
session_hash_str = str(req.session_hash) if hasattr(req, 'session_hash') and req.session_hash else f"api_call_{np.random.randint(10000)}"
|
162 |
+
user_dir = os.path.join(TMP_DIR, session_hash_str)
|
163 |
+
os.makedirs(user_dir, exist_ok=True) # Ensure directory exists
|
164 |
+
|
165 |
gs, mesh = unpack_state(state)
|
166 |
glb = postprocessing_utils.to_glb(gs, mesh, simplify=mesh_simplify, texture_size=texture_size, verbose=False)
|
167 |
glb_path = os.path.join(user_dir, 'sample.glb')
|
168 |
+
try:
|
169 |
+
glb.export(glb_path) # Now the directory should exist
|
170 |
+
except FileNotFoundError:
|
171 |
+
print(f"ERROR: Directory {user_dir} still not found before glb.export!", file=sys.stderr)
|
172 |
+
raise
|
173 |
torch.cuda.empty_cache()
|
174 |
return glb_path, glb_path
|
175 |
|
|
|
185 |
Returns:
|
186 |
str: The path to the extracted Gaussian file.
|
187 |
"""
|
188 |
+
# --- Determine user_dir robustly ---
|
189 |
+
session_hash_str = str(req.session_hash) if hasattr(req, 'session_hash') and req.session_hash else f"api_call_{np.random.randint(10000)}"
|
190 |
+
user_dir = os.path.join(TMP_DIR, session_hash_str)
|
191 |
+
os.makedirs(user_dir, exist_ok=True) # Ensure directory exists
|
192 |
+
|
193 |
gs, _ = unpack_state(state)
|
194 |
gaussian_path = os.path.join(user_dir, 'sample.ply')
|
195 |
+
try:
|
196 |
+
gs.save_ply(gaussian_path) # Now the directory should exist
|
197 |
+
except FileNotFoundError:
|
198 |
+
print(f"ERROR: Directory {user_dir} still not found before gs.save_ply!", file=sys.stderr)
|
199 |
+
raise
|
200 |
torch.cuda.empty_cache()
|
201 |
return gaussian_path, gaussian_path
|
202 |
|