Spaces:
Build error
Build error
fix
Browse files66 unmodified lines6768697071721 unmodified line7475767778798081828384853 unmodified lines8990919293949596979863 unmodified lines16216316416516616716816966 unmodified linesreturn seed# process imagedef process_image(input_image):input_image = np.array(input_image) # uint8# bg removal if there is no alpha channel1 unmodified lineinput_image = rembg.remove(input_image, session=bg_remover) # [H, W, 4]mask = input_image[..., -1] > 0image = recenter_foreground(input_image, mask, border_ratio=0.1)image = cv2.resize(image, (518, 518), interpolation=cv2.INTER_AREA)return image# process generation@spaces.GPU(duration=60)def process_3d(input_image, num_steps=50, cfg_scale=7.0, grid_res=384, seed=42, simplify_mesh=False, target_num_faces=100000):# seedkiui.seed_everything(seed)3 unmodified linesoutput_glb_path = f"output/partpacker_{datetime.now().strftime('%Y%m%d_%H%M%S')}.glb"# input image (assume processed to RGBA uint8)image = np.array(input_image)image = image.astype(np.float32) / 255.0image = image[..., :3] * image[..., 3:4] + (1 - image[..., 3:4]) # white backgroundimage = (image * 255).astype(np.uint8)image_tensor = torch.from_numpy(image).permute(2, 0, 1).contiguous().unsqueeze(0).float().cuda()data = {"cond_images": image_tensor}63 unmodified lineswith gr.Column(scale=1):with gr.Row():# input imageinput_image = gr.Image(label="Input Image")seg_image = gr.Image(label="Segmentation Result", type="pil", format="png", interactive=False, image_mode="RGBA")with gr.Accordion("Settings", open=True):# inference stepsnum_steps = gr.Slider(label="Inference steps", minimum=1, maximum=100, step=1, value=50)66 unmodified lines676869707172731 unmodified line7576777879808182838485863 unmodified lines909192939495969763 unmodified lines16116216316416516616716866 unmodified linesreturn seed# process image@spaces.GPU(duration=10)def process_image(input_image):input_image = np.array(input_image) # uint8# bg removal if there is no alpha channel1 unmodified lineinput_image = rembg.remove(input_image, session=bg_remover) # [H, W, 4]mask = input_image[..., -1] > 0image = recenter_foreground(input_image, mask, border_ratio=0.1)image = cv2.resize(image, (518, 518), interpolation=cv2.INTER_LINEAR)return image# process generation@spaces.GPU(duration=60)def process_3d(input_image, num_steps=50, cfg_scale=7, grid_res=384, seed=42, simplify_mesh=False, target_num_faces=100000):# seedkiui.seed_everything(seed)3 unmodified linesoutput_glb_path = f"output/partpacker_{datetime.now().strftime('%Y%m%d_%H%M%S')}.glb"# input image (assume processed to RGBA uint8)image = input_image.astype(np.float32) / 255.0image = image[..., :3] * image[..., 3:4] + (1 - image[..., 3:4]) # white backgroundimage_tensor = torch.from_numpy(image).permute(2, 0, 1).contiguous().unsqueeze(0).float().cuda()data = {"cond_images": image_tensor}63 unmodified lineswith gr.Column(scale=1):with gr.Row():# input imageinput_image = gr.Image(label="Input Image", type="numpy")seg_image = gr.Image(label="Segmentation Result", type="numpy", format="png", interactive=False, image_mode="RGBA")with gr.Accordion("Settings", open=True):# inference stepsnum_steps = gr.Slider(label="Inference steps", minimum=1, maximum=100, step=1, value=50)
app.py+6-7