dkatz2391 commited on
Commit
6c43284
·
verified ·
1 Parent(s): 1a9c5b9

mimic the naimate rig output stage

Browse files
Files changed (1) hide show
  1. app.py +35 -11
app.py CHANGED
@@ -18,6 +18,7 @@ from gradio.processing_utils import move_resource_to_block_cache
18
  import traceback
19
  import sys
20
  import logging
 
21
 
22
 
23
  MAX_SEED = np.iinfo(np.int32).max
@@ -189,12 +190,15 @@ def generate_and_extract_glb(
189
  req: gr.Request,
190
  ) -> str:
191
  """
192
- Runs the full text_to_3d and extract_glb pipeline internally.
 
193
  """
194
  request_hash = str(req.session_hash)[:8]
195
  logging.info(f"[{request_hash}] ENTER generate_and_extract_glb")
196
  logging.info(f"[{request_hash}] Received parameters: prompt='{prompt}', seed={seed}, simplify={mesh_simplify}, tex_size={texture_size}, ...")
197
 
 
 
198
  try:
199
  logging.info(f"[{request_hash}] Calling internal text_to_3d...")
200
  state, _ = text_to_3d(
@@ -213,20 +217,40 @@ def generate_and_extract_glb(
213
  if glb_path is None:
214
  logging.error(f"[{request_hash}] Internal extract_glb returned None path!")
215
  raise ValueError("Internal extract_glb failed to return GLB path")
216
- logging.info(f"[{request_hash}] Internal extract_glb completed. Original GLB path: {glb_path}")
 
 
 
217
 
 
 
218
  try:
219
- cached_glb_path = move_resource_to_block_cache(glb_path, demo)
220
- logging.info(f"[{request_hash}] Copied GLB to Gradio cache: {cached_glb_path}")
221
- logging.info(f"[{request_hash}] EXIT generate_and_extract_glb - Returning cached path: {cached_glb_path}")
222
- return cached_glb_path
223
- except Exception as cache_err:
224
- logging.error(f"[{request_hash}] ERROR copying GLB to Gradio cache: {cache_err}", exc_info=True)
225
- logging.warning(f"[{request_hash}] Falling back to returning original path: {glb_path}")
226
- return glb_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
 
228
  except Exception as e:
229
- logging.error(f"[{request_hash}] ERROR in generate_and_extract_glb: {e}", exc_info=True)
230
  raise gr.Error(f"Pipeline failed: {e}")
231
 
232
 
 
18
  import traceback
19
  import sys
20
  import logging
21
+ import requests
22
 
23
 
24
  MAX_SEED = np.iinfo(np.int32).max
 
190
  req: gr.Request,
191
  ) -> str:
192
  """
193
+ Runs the full text_to_3d and extract_glb pipeline internally,
194
+ then uploads the GLB to the Node.js server and returns the persistent URL.
195
  """
196
  request_hash = str(req.session_hash)[:8]
197
  logging.info(f"[{request_hash}] ENTER generate_and_extract_glb")
198
  logging.info(f"[{request_hash}] Received parameters: prompt='{prompt}', seed={seed}, simplify={mesh_simplify}, tex_size={texture_size}, ...")
199
 
200
+ NODE_SERVER_UPLOAD_URL = "https://viverse-backend.onrender.com/api/upload-rigged-model"
201
+
202
  try:
203
  logging.info(f"[{request_hash}] Calling internal text_to_3d...")
204
  state, _ = text_to_3d(
 
217
  if glb_path is None:
218
  logging.error(f"[{request_hash}] Internal extract_glb returned None path!")
219
  raise ValueError("Internal extract_glb failed to return GLB path")
220
+ if not os.path.isfile(glb_path):
221
+ logging.error(f"[{request_hash}] GLB file not found at path: {glb_path}")
222
+ raise FileNotFoundError(f"Generated GLB file not found at {glb_path}")
223
+ logging.info(f"[{request_hash}] Internal extract_glb completed. GLB path: {glb_path}")
224
 
225
+ logging.info(f"[{request_hash}] Uploading GLB from {glb_path} to {NODE_SERVER_UPLOAD_URL}")
226
+ persistent_url = None
227
  try:
228
+ with open(glb_path, "rb") as f:
229
+ files = {"modelFile": (os.path.basename(glb_path), f, "model/gltf-binary")}
230
+ payload = {"clientType": "playcanvas"}
231
+ response = requests.post(NODE_SERVER_UPLOAD_URL, files=files, data=payload)
232
+ response.raise_for_status()
233
+ result = response.json()
234
+ persistent_url = result.get("persistentUrl")
235
+ if not persistent_url:
236
+ logging.error(f"[{request_hash}] No persistent URL in Node.js server response: {result}")
237
+ raise ValueError("Upload successful, but no persistent URL returned")
238
+ logging.info(f"[{request_hash}] Successfully uploaded to Node server. Persistent URL: {persistent_url}")
239
+ except requests.exceptions.RequestException as upload_err:
240
+ logging.error(f"[{request_hash}] FAILED to upload GLB to Node server: {upload_err}")
241
+ if hasattr(upload_err, 'response') and upload_err.response is not None:
242
+ logging.error(f"[{request_hash}] Node server response status: {upload_err.response.status_code}")
243
+ logging.error(f"[{request_hash}] Node server response text: {upload_err.response.text}")
244
+ raise gr.Error(f"Failed to upload result to backend server: {upload_err}")
245
+ except Exception as e:
246
+ logging.error(f"[{request_hash}] UNEXPECTED error during upload: {e}", exc_info=True)
247
+ raise gr.Error(f"Unexpected error during upload: {e}")
248
+
249
+ logging.info(f"[{request_hash}] EXIT generate_and_extract_glb - Returning persistent URL: {persistent_url}")
250
+ return persistent_url
251
 
252
  except Exception as e:
253
+ logging.error(f"[{request_hash}] ERROR in generate_and_extract_glb pipeline: {e}", exc_info=True)
254
  raise gr.Error(f"Pipeline failed: {e}")
255
 
256