luh1124 commited on
Commit
2bcccaf
·
1 Parent(s): 516a9fa

HF Space: load pipelines before module-level demo, fix import entry

Browse files

- Move from_pretrained and device placement before build_app() so import finds demo and PIPELINE
- Use torch.cuda.is_available() for cuda vs cpu (works local and when import has no GPU)
- __main__ only runs demo.launch()

Made-with: Cursor

Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -989,16 +989,20 @@ def build_app() -> gr.Blocks:
989
  return demo
990
 
991
 
992
- demo = build_app()
993
-
994
- if __name__ == "__main__":
995
-
996
- PIPELINE = NeARImageToRelightable3DPipeline.from_pretrained("luh0502/NeAR")
997
- GEOMETRY_PIPELINE = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained("tencent/Hunyuan3D-2.1")
998
 
 
999
  PIPELINE.to("cuda")
1000
  GEOMETRY_PIPELINE.to("cuda")
 
 
 
1001
 
 
 
 
 
1002
  demo.launch(
1003
  mcp_server=True
1004
  )
 
989
  return demo
990
 
991
 
992
+ PIPELINE = NeARImageToRelightable3DPipeline.from_pretrained("luh0502/NeAR")
993
+ GEOMETRY_PIPELINE = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained("tencent/Hunyuan3D-2.1")
 
 
 
 
994
 
995
+ if torch.cuda.is_available():
996
  PIPELINE.to("cuda")
997
  GEOMETRY_PIPELINE.to("cuda")
998
+ else:
999
+ PIPELINE.to("cpu")
1000
+ GEOMETRY_PIPELINE.to("cpu")
1001
 
1002
+ demo = build_app()
1003
+
1004
+
1005
+ if __name__ == "__main__":
1006
  demo.launch(
1007
  mcp_server=True
1008
  )