ashawkey commited on
Commit
52362ee
·
1 Parent(s): 70954d6

update param

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -67,7 +67,6 @@ def get_random_seed(randomize_seed, seed):
67
  return seed
68
 
69
  # process image
70
- @spaces.GPU(duration=10)
71
  def process_image(input_image):
72
  input_image = np.array(input_image) # uint8
73
  # bg removal if there is no alpha channel
@@ -75,12 +74,12 @@ def process_image(input_image):
75
  input_image = rembg.remove(input_image, session=bg_remover) # [H, W, 4]
76
  mask = input_image[..., -1] > 0
77
  image = recenter_foreground(input_image, mask, border_ratio=0.1)
78
- image = cv2.resize(image, (518, 518), interpolation=cv2.INTER_LINEAR)
79
  return image
80
 
81
  # process generation
82
- @spaces.GPU(duration=120)
83
- def process_3d(input_image, num_steps=30, cfg_scale=7.5, grid_res=384, seed=42, simplify_mesh=False, target_num_faces=100000):
84
 
85
  # seed
86
  kiui.seed_everything(seed)
@@ -90,8 +89,10 @@ def process_3d(input_image, num_steps=30, cfg_scale=7.5, grid_res=384, seed=42,
90
  output_glb_path = f"output/partpacker_{datetime.now().strftime('%Y%m%d_%H%M%S')}.glb"
91
 
92
  # input image (assume processed to RGBA uint8)
93
- image = input_image.astype(np.float32) / 255.0
 
94
  image = image[..., :3] * image[..., 3:4] + (1 - image[..., 3:4]) # white background
 
95
  image_tensor = torch.from_numpy(image).permute(2, 0, 1).contiguous().unsqueeze(0).float().cuda()
96
 
97
  data = {"cond_images": image_tensor}
@@ -161,11 +162,11 @@ with block:
161
  with gr.Column(scale=1):
162
  with gr.Row():
163
  # input image
164
- input_image = gr.Image(label="Input Image", type="numpy")
165
- seg_image = gr.Image(label="Segmentation Result", type="numpy", format="png", interactive=False, image_mode="RGBA")
166
  with gr.Accordion("Settings", open=True):
167
  # inference steps
168
- num_steps = gr.Slider(label="Inference steps", minimum=1, maximum=100, step=1, value=30)
169
  # cfg scale
170
  cfg_scale = gr.Slider(label="CFG scale", minimum=2, maximum=10, step=0.1, value=7.0)
171
  # grid resolution
 
67
  return seed
68
 
69
  # process image
 
70
  def process_image(input_image):
71
  input_image = np.array(input_image) # uint8
72
  # bg removal if there is no alpha channel
 
74
  input_image = rembg.remove(input_image, session=bg_remover) # [H, W, 4]
75
  mask = input_image[..., -1] > 0
76
  image = recenter_foreground(input_image, mask, border_ratio=0.1)
77
+ image = cv2.resize(image, (518, 518), interpolation=cv2.INTER_AREA)
78
  return image
79
 
80
  # process generation
81
+ @spaces.GPU(duration=60)
82
+ def process_3d(input_image, num_steps=50, cfg_scale=7.0, grid_res=384, seed=42, simplify_mesh=False, target_num_faces=100000):
83
 
84
  # seed
85
  kiui.seed_everything(seed)
 
89
  output_glb_path = f"output/partpacker_{datetime.now().strftime('%Y%m%d_%H%M%S')}.glb"
90
 
91
  # input image (assume processed to RGBA uint8)
92
+ image = np.array(input_image)
93
+ image = image.astype(np.float32) / 255.0
94
  image = image[..., :3] * image[..., 3:4] + (1 - image[..., 3:4]) # white background
95
+ image = (image * 255).astype(np.uint8)
96
  image_tensor = torch.from_numpy(image).permute(2, 0, 1).contiguous().unsqueeze(0).float().cuda()
97
 
98
  data = {"cond_images": image_tensor}
 
162
  with gr.Column(scale=1):
163
  with gr.Row():
164
  # input image
165
+ input_image = gr.Image(label="Input Image")
166
+ seg_image = gr.Image(label="Segmentation Result", type="pil", format="png", interactive=False, image_mode="RGBA")
167
  with gr.Accordion("Settings", open=True):
168
  # inference steps
169
+ num_steps = gr.Slider(label="Inference steps", minimum=1, maximum=100, step=1, value=50)
170
  # cfg scale
171
  cfg_scale = gr.Slider(label="CFG scale", minimum=2, maximum=10, step=0.1, value=7.0)
172
  # grid resolution