Spaces:
Running
Running
update.
Browse files108 unmodified lines10911011111211211311411513 unmodified lines1291301311321321331341351361371381391391401411421 unmodified line14414514614714714814915015 unmodified lines16616716816916917017117229 unmodified lines20220320420520520620720839 unmodified lines248249250251251252253254108 unmodified lines only_center_face = False draw_box = False detection_model = "retinaface_resnet50" print(image, background_enhance, face_upsample, upscale, codeformer_fidelity) print('Inp:', image, background_enhance, face_upsample, upscale, codeformer_fidelity)
upscale = int(upscale) # covert type to int if upscale > 4:13 unmodified lines
img = cv2.imread(str(image), cv2.IMREAD_COLOR)
print('Image size:', img.shape) print('\timage size:', img.shape)
if has_aligned: # the input faces are already cropped and aligned img = cv2.resize(img, (512, 512), interpolation=cv2.INTER_LINEAR) face_helper.is_gray = is_gray(img, threshold=5) if face_helper.is_gray: print('Grayscale input: True') print('\tgrayscale input: True') face_helper.cropped_faces = [img] else: face_helper.read_image(img)1 unmodified line num_det_faces = face_helper.get_face_landmarks_5( only_center_face=only_center_face, resize=640, eye_dist_threshold=5 ) print(f"\tdetect {num_det_faces} faces") print(f'\tdetect {num_det_faces} faces') # align and warp each face face_helper.align_warp_face()
15 unmodified lines del output torch.cuda.empty_cache() except RuntimeError as error: print(f"\tFailed inference for CodeFormer: {error}") print(f"Failed inference for CodeFormer: {error}") restored_face = tensor2img( cropped_face_t, rgb2bgr=True, min_max=(-1, 1) )29 unmodified lines restored_img = cv2.cvtColor(restored_img, cv2.COLOR_BGR2RGB) return restored_img, save_path except Exception as error: print('global exception', error) print('Global exception', error) return None, None
39 unmodified lines gr.inputs.Checkbox(default=True, label="Background_Enhance"), gr.inputs.Checkbox(default=True, label="Face_Upsample"), gr.inputs.Number(default=2, label="Rescaling_Factor (up to 4)"), gr.Slider(0, 1, value=0.5, step=0.01, label='Codeformer_Fidelity: 0 better quality, 1 better identity') gr.Slider(0, 1, value=0.5, step=0.01, label='Codeformer_Fidelity (0 for better quality, 1 for better identity)') ], [ gr.outputs.Image(type="numpy", label="Output"), gr.outputs.File(label="Download the output")app.py+7-7