Spaces:
Sleeping
Sleeping
update.
Browse files108 unmodified lines10911011111211311411513 unmodified lines1291301311321331341351361371381391401411421 unmodified line14414514614714814915015 unmodified lines16616716816917017117229 unmodified lines20220320420520620720839 unmodified lines248249250251252253254108 unmodified linesonly_center_face = Falsedraw_box = Falsedetection_model = "retinaface_resnet50"print(image, background_enhance, face_upsample, upscale, codeformer_fidelity)upscale = int(upscale) # covert type to intif upscale > 4:13 unmodified linesimg = cv2.imread(str(image), cv2.IMREAD_COLOR)print('Image size:', img.shape)if has_aligned:# the input faces are already cropped and alignedimg = 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')face_helper.cropped_faces = [img]else:face_helper.read_image(img)1 unmodified linenum_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")# align and warp each faceface_helper.align_warp_face()15 unmodified linesdel outputtorch.cuda.empty_cache()except RuntimeError as error:print(f"\tFailed inference for CodeFormer: {error}")restored_face = tensor2img(cropped_face_t, rgb2bgr=True, min_max=(-1, 1))29 unmodified linesrestored_img = cv2.cvtColor(restored_img, cv2.COLOR_BGR2RGB)return restored_img, save_pathexcept Exception as error:print('global exception', error)return None, None39 unmodified linesgr.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.outputs.Image(type="numpy", label="Output"),gr.outputs.File(label="Download the output")108 unmodified lines10911011111211311411513 unmodified lines1291301311321331341351361371381391401411421 unmodified line14414514614714814915015 unmodified lines16616716816917017117229 unmodified lines20220320420520620720839 unmodified lines248249250251252253254108 unmodified linesonly_center_face = Falsedraw_box = Falsedetection_model = "retinaface_resnet50"print('Inp:', image, background_enhance, face_upsample, upscale, codeformer_fidelity)upscale = int(upscale) # covert type to intif upscale > 4:13 unmodified linesimg = cv2.imread(str(image), cv2.IMREAD_COLOR)print('\timage size:', img.shape)if has_aligned:# the input faces are already cropped and alignedimg = cv2.resize(img, (512, 512), interpolation=cv2.INTER_LINEAR)face_helper.is_gray = is_gray(img, threshold=5)if face_helper.is_gray:print('\tgrayscale input: True')face_helper.cropped_faces = [img]else:face_helper.read_image(img)1 unmodified linenum_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')# align and warp each faceface_helper.align_warp_face()15 unmodified linesdel outputtorch.cuda.empty_cache()except RuntimeError as error:print(f"Failed inference for CodeFormer: {error}")restored_face = tensor2img(cropped_face_t, rgb2bgr=True, min_max=(-1, 1))29 unmodified linesrestored_img = cv2.cvtColor(restored_img, cv2.COLOR_BGR2RGB)return restored_img, save_pathexcept Exception as error:print('Global exception', error)return None, None39 unmodified linesgr.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 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