dkatz2391 commited on
Commit
0f79bfb
·
verified ·
1 Parent(s): 64a7809

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -10
app.py CHANGED
@@ -32,6 +32,8 @@ pipeline = None
32
  logging.basicConfig(level=logging.INFO)
33
  logger = logging.getLogger(__name__)
34
 
 
 
35
  def start_session(req: gr.Request):
36
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
37
  os.makedirs(user_dir, exist_ok=True)
@@ -313,15 +315,39 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
313
 
314
  # Launch the Gradio app and FastAPI server
315
  if __name__ == "__main__":
316
- logger.info("Initializing Trellis Pipeline...")
317
- # Make pipeline global so Gradio functions and API endpoint can access it
318
- pipeline = TrellisTextTo3DPipeline.from_pretrained("JeffreyXiang/TRELLIS-text-xlarge")
319
- pipeline.cuda()
320
- logger.info("Trellis Pipeline Initialized.")
321
-
322
- # Start the background API server using the integration module
323
- trellis_fastAPI_integration.start_api_thread(pipeline)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
 
325
  # Launch the Gradio interface (blocking call)
326
- logger.info("Launching Gradio Demo...")
327
- demo.launch()
 
 
 
 
 
32
  logging.basicConfig(level=logging.INFO)
33
  logger = logging.getLogger(__name__)
34
 
35
+ logger.info("Trellis App: Script starting.")
36
+
37
  def start_session(req: gr.Request):
38
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
39
  os.makedirs(user_dir, exist_ok=True)
 
315
 
316
  # Launch the Gradio app and FastAPI server
317
  if __name__ == "__main__":
318
+ logger.info("Trellis App: Initializing Trellis Pipeline...")
319
+ try:
320
+ # Make pipeline global so Gradio functions and API endpoint can access it
321
+ pipeline = TrellisTextTo3DPipeline.from_pretrained("JeffreyXiang/TRELLIS-text-xlarge")
322
+ pipeline.cuda()
323
+ logger.info("Trellis App: Trellis Pipeline Initialized successfully.")
324
+ except Exception as e:
325
+ logger.error(f"Trellis App: FATAL ERROR initializing pipeline: {e}", exc_info=True)
326
+ pipeline = None # Ensure pipeline is None if initialization failed
327
+ # Optionally exit if pipeline is critical
328
+ # import sys
329
+ # sys.exit("Pipeline initialization failed.")
330
+
331
+ # Start the background API server using the integration module only if pipeline loaded
332
+ if pipeline:
333
+ logger.info("Trellis App: Attempting to start FastAPI server thread...")
334
+ try:
335
+ api_thread = trellis_fastAPI_integration.start_api_thread(pipeline)
336
+ if api_thread and api_thread.is_alive():
337
+ logger.info("Trellis App: FastAPI server thread started successfully (is_alive check passed).")
338
+ elif api_thread:
339
+ logger.warning("Trellis App: FastAPI server thread was created but is not alive shortly after starting.")
340
+ else:
341
+ logger.error("Trellis App: start_api_thread returned None, thread not created.")
342
+ except Exception as e:
343
+ logger.error(f"Trellis App: Error occurred during start_api_thread call: {e}", exc_info=True)
344
+ else:
345
+ logger.error("Trellis App: Skipping FastAPI server start because pipeline failed to initialize.")
346
 
347
  # Launch the Gradio interface (blocking call)
348
+ logger.info("Trellis App: Launching Gradio Demo...")
349
+ try:
350
+ demo.launch()
351
+ logger.info("Trellis App: Gradio Demo launched.") # This might not be reached if launch blocks indefinitely
352
+ except Exception as e:
353
+ logger.error(f"Trellis App: Error launching Gradio demo: {e}", exc_info=True)