prithivMLmods commited on
Commit
a5c779b
·
verified ·
1 Parent(s): 461126e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -95,7 +95,9 @@ orange_red_theme = OrangeRedTheme()
95
  # Environment Config
96
  os.environ["OPENCV_IO_ENABLE_OPENEXR"] = '1'
97
  os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
98
- os.environ["ATTN_BACKEND"] = "flash_attn_3"
 
 
99
  os.environ["FLEX_GEMM_AUTOTUNE_CACHE_PATH"] = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'autotune_cache.json')
100
  os.environ["FLEX_GEMM_AUTOTUNER_VERBOSE"] = '1'
101
 
@@ -301,23 +303,19 @@ def generate_3d(
301
  progress(0.95, desc="Creating Rerun Visualization...")
302
  rrd_path = os.path.join(user_dir, f'trellis_output_{timestamp}.rrd')
303
 
304
- # Initialize Rerun
305
  rr.init(f"Trellis_Session_{timestamp}", spawn=False)
306
 
307
- # Setup View Coordinates (Z-UP is standard for Trellis)
308
  rr.log("world", rr.ViewCoordinates.RIGHT_HAND_Z_UP, static=True)
309
 
310
- # Add Reference Axis
311
  rr.log("world/axis", rr.Arrows3D(
312
  vectors=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
313
  colors=[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
314
  radii=0.02
315
  ), static=True)
316
 
317
- # Log the generated 3D model
318
  rr.log("world/model", rr.Asset3D(path=glb_path))
319
 
320
- # Save to RRD file for Gradio
321
  rr.save(rrd_path)
322
 
323
  torch.cuda.empty_cache()
@@ -325,7 +323,11 @@ def generate_3d(
325
 
326
  except Exception as e:
327
  torch.cuda.empty_cache()
328
- raise gr.Error(f"Generation failed: {str(e)}")
 
 
 
 
329
 
330
  css="""
331
  #col-container {
@@ -389,7 +391,6 @@ if __name__ == "__main__":
389
 
390
  with gr.Column(scale=2):
391
  gr.Markdown("### 3D Output (Rerun Viewer)")
392
- # Replaced Model3D with Rerun Component
393
  rerun_output = Rerun(
394
  label="Rerun 3D Viewer",
395
  height=600
 
95
  # Environment Config
96
  os.environ["OPENCV_IO_ENABLE_OPENEXR"] = '1'
97
  os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
98
+ # FIXED: Changed ATTN_BACKEND from 'flash_attn_3' to 'xformers' to avoid import error.
99
+ # If 'xformers' also fails, try changing this to 'sdpa'
100
+ os.environ["ATTN_BACKEND"] = "xformers"
101
  os.environ["FLEX_GEMM_AUTOTUNE_CACHE_PATH"] = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'autotune_cache.json')
102
  os.environ["FLEX_GEMM_AUTOTUNER_VERBOSE"] = '1'
103
 
 
303
  progress(0.95, desc="Creating Rerun Visualization...")
304
  rrd_path = os.path.join(user_dir, f'trellis_output_{timestamp}.rrd')
305
 
 
306
  rr.init(f"Trellis_Session_{timestamp}", spawn=False)
307
 
308
+ # Z-UP is standard for Trellis
309
  rr.log("world", rr.ViewCoordinates.RIGHT_HAND_Z_UP, static=True)
310
 
 
311
  rr.log("world/axis", rr.Arrows3D(
312
  vectors=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
313
  colors=[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
314
  radii=0.02
315
  ), static=True)
316
 
 
317
  rr.log("world/model", rr.Asset3D(path=glb_path))
318
 
 
319
  rr.save(rrd_path)
320
 
321
  torch.cuda.empty_cache()
 
323
 
324
  except Exception as e:
325
  torch.cuda.empty_cache()
326
+ # More descriptive error handling
327
+ error_msg = str(e)
328
+ if "No module named 'flash_attn'" in error_msg:
329
+ error_msg += " (Try changing ATTN_BACKEND to 'sdpa' in the code)"
330
+ raise gr.Error(f"Generation failed: {error_msg}")
331
 
332
  css="""
333
  #col-container {
 
391
 
392
  with gr.Column(scale=2):
393
  gr.Markdown("### 3D Output (Rerun Viewer)")
 
394
  rerun_output = Rerun(
395
  label="Rerun 3D Viewer",
396
  height=600