murcherful commited on
Commit
45ce04d
·
1 Parent(s): 4210dc2

fix req and state

Browse files
Files changed (2) hide show
  1. app.py +23 -32
  2. requirements.txt +3 -2
app.py CHANGED
@@ -8,50 +8,41 @@ from pathlib import Path
8
  import torch
9
  import pytorch_lightning as pl
10
  import spaces
11
- # from spaces import zero
12
- # zero.startup()
13
- # import torch.multiprocessing as mp
14
- # mp.set_start_method('spawn')
15
- # print('using torch spawm')
16
- # print('zero gpu startup')
17
 
18
  sys.path.append('P3-SAM')
19
  from demo.auto_mask import AutoMask
20
  # from demo.auto_mask_no_postprocess import AutoMask as AutoMaskNoPostProcess
21
- # sys.path.append('XPart')
22
- # from partgen.partformer_pipeline import PartFormerPipeline
23
- # from partgen.utils.misc import get_config_from_file
24
- print('no automask no postprocess')
25
 
26
  automask = AutoMask()
27
  # automask_no_postprocess = AutoMaskNoPostProcess(automask_instance=automask)
28
 
29
- # def _load_pipeline():
30
- # pl.seed_everything(2026, workers=True)
31
- # cfg_path = str(Path(__file__).parent / "XPart/partgen/config" / "infer.yaml")
32
- # config = get_config_from_file(cfg_path)
33
- # assert hasattr(config, "ckpt") or hasattr(
34
- # config, "ckpt_path"
35
- # ), "ckpt or ckpt_path must be specified in config"
36
- # pipeline = PartFormerPipeline.from_pretrained(
37
- # config=config,
38
- # verbose=True,
39
- # ignore_keys=config.get("ignore_keys", []),
40
- # )
41
-
42
- # device = "cuda"
43
- # pipeline.to(device=device, dtype=torch.float32)
44
- # return pipeline
45
 
46
- # _PIPELINE = _load_pipeline()
 
 
47
 
48
- print('no xpart pipeline')
49
 
50
  output_path = 'P3-SAM/results/gradio'
51
  os.makedirs(output_path, exist_ok=True)
52
 
53
  @spaces.GPU
54
- def segment(mesh_path, connectivity=True, postprocess=True, postprocess_threshold=0.95, seed=42, gr_state=None):
55
  if mesh_path is None:
56
  gr.Warning("No Input Mesh")
57
  gr_state[0] = (None, None)
@@ -82,8 +73,8 @@ def segment(mesh_path, connectivity=True, postprocess=True, postprocess_threshol
82
  mesh_save.export(file_path)
83
  face_id_save_path = os.path.join(output_path, 'face_id.npy')
84
  np.save(face_id_save_path, face_ids)
85
- gr_state[0] = (aabb, mesh_path)
86
- return file_path, face_id_save_path
87
 
88
  @spaces.GPU
89
  def generate(mesh_path, seed=42, gr_state=None):
@@ -192,7 +183,7 @@ Input a mesh, segment it using P3-SAM on the left, and push the "Generate" butto
192
  xpart_output_exploded = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="Exploded Object")
193
  xpart_seed = gr.Number(value=42, label="Random Seed")
194
  gr_state = gr.State(value=[(None, None)])
195
- p3sam_button.click(segment, inputs=[p3sam_input, p3sam_conectivity, p3sam_postprocess, p3sam_postprocess_threshold, p3sam_seed, gr_state], outputs=[p3sam_output, p3sam_face_id_output])
196
  xpart_button.click(generate, inputs=[p3sam_input, xpart_seed, gr_state], outputs=[xpart_output, xpart_output_bbox, xpart_output_exploded])
197
 
198
 
 
8
  import torch
9
  import pytorch_lightning as pl
10
  import spaces
 
 
 
 
 
 
11
 
12
  sys.path.append('P3-SAM')
13
  from demo.auto_mask import AutoMask
14
  # from demo.auto_mask_no_postprocess import AutoMask as AutoMaskNoPostProcess
15
+ sys.path.append('XPart')
16
+ from partgen.partformer_pipeline import PartFormerPipeline
17
+ from partgen.utils.misc import get_config_from_file
 
18
 
19
  automask = AutoMask()
20
  # automask_no_postprocess = AutoMaskNoPostProcess(automask_instance=automask)
21
 
22
+ def _load_pipeline():
23
+ pl.seed_everything(2026, workers=True)
24
+ cfg_path = str(Path(__file__).parent / "XPart/partgen/config" / "infer.yaml")
25
+ config = get_config_from_file(cfg_path)
26
+ assert hasattr(config, "ckpt") or hasattr(
27
+ config, "ckpt_path"
28
+ ), "ckpt or ckpt_path must be specified in config"
29
+ pipeline = PartFormerPipeline.from_pretrained(
30
+ config=config,
31
+ verbose=True,
32
+ ignore_keys=config.get("ignore_keys", []),
33
+ )
 
 
 
 
34
 
35
+ device = "cuda"
36
+ pipeline.to(device=device, dtype=torch.float32)
37
+ return pipeline
38
 
39
+ _PIPELINE = _load_pipeline()
40
 
41
  output_path = 'P3-SAM/results/gradio'
42
  os.makedirs(output_path, exist_ok=True)
43
 
44
  @spaces.GPU
45
+ def segment(mesh_path, connectivity=True, postprocess=True, postprocess_threshold=0.95, seed=42):
46
  if mesh_path is None:
47
  gr.Warning("No Input Mesh")
48
  gr_state[0] = (None, None)
 
73
  mesh_save.export(file_path)
74
  face_id_save_path = os.path.join(output_path, 'face_id.npy')
75
  np.save(face_id_save_path, face_ids)
76
+ gr_state = [(aabb, mesh_path)]
77
+ return file_path, face_id_save_path, gr_state
78
 
79
  @spaces.GPU
80
  def generate(mesh_path, seed=42, gr_state=None):
 
183
  xpart_output_exploded = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="Exploded Object")
184
  xpart_seed = gr.Number(value=42, label="Random Seed")
185
  gr_state = gr.State(value=[(None, None)])
186
+ p3sam_button.click(segment, inputs=[p3sam_input, p3sam_conectivity, p3sam_postprocess, p3sam_postprocess_threshold, p3sam_seed], outputs=[p3sam_output, p3sam_face_id_output, gr_state])
187
  xpart_button.click(generate, inputs=[p3sam_input, xpart_seed, gr_state], outputs=[xpart_output, xpart_output_bbox, xpart_output_exploded])
188
 
189
 
requirements.txt CHANGED
@@ -43,5 +43,6 @@ scikit-image
43
 
44
  # sonata
45
  spconv-cu126
46
- torch-scatter -f https://data.pyg.org/whl/torch-2.8.0+cu128.html
47
- git+https://github.com/Dao-AILab/flash-attention.git
 
 
43
 
44
  # sonata
45
  spconv-cu126
46
+ torch-scatter -f https://data.pyg.org/whl/torch-2.8.0+cu129.html
47
+ git+https://github.com/Dao-AILab/flash-attention.git
48
+ torch-cluster -f https://data.pyg.org/whl/torch-2.8.0+cu129.html