import os os.makedirs("./checkpoints", exist_ok=True) os.system("wget https://huggingface.co/wmpscc/StyleGene/resolve/main/e4e_ffhq_encode.pt -o ./checkpoints/e4e_ffhq_encode.pt") os.system("wget https://huggingface.co/wmpscc/StyleGene/resolve/main/res34_fair_align_multi_7_20190809.pt -o ./checkpoints/res34_fair_align_multi_7_20190809.pt") os.system("wget https://huggingface.co/wmpscc/StyleGene/resolve/main/shape_predictor_68_face_landmarks.dat.bz2 -o ./checkpoints/shape_predictor_68_face_landmarks.dat.bz2") os.system("wget https://huggingface.co/wmpscc/StyleGene/resolve/main/stylegan2-ffhq-config-f.pt -o ./checkpoints/stylegan2-ffhq-config-f.pt") os.system("wget https://huggingface.co/wmpscc/StyleGene/resolve/main/stylegene_N18.ckpt -o ./checkpoints/stylegene_N18.ckpt") os.system("wget https://huggingface.co/wmpscc/StyleGene/resolve/main/geneFactorPool.pkl -o ./checkpoints/geneFactorPool.pkl") import gradio as gr from models.stylegene.api import synthesize_descendant description = """

StyleGene: Crossover and Mutation of Region-Level Facial Genes for Kinship Face Synthesis
[Project Page] [Paper] [GitHub]
Tips: One picture should have only one face.

""" block = gr.Blocks() with block: gr.HTML(description) with gr.Row(): with gr.Column(): gr.Markdown("### Upload photos of father and mother") with gr.Row(): img1 = gr.Image(label="Father") img2 = gr.Image(label="Mother") gr.Markdown("### Select the child's age and gender") with gr.Row(): age = gr.Dropdown(label="Age", choices=["0-2", "3-9", "10-19", "20-29", "30-39", "40-49", "50-59", "60-69", "70+"], value="3-9") gender = gr.Dropdown(label="Gender", choices=["male", "female"], value="female") gr.Markdown("### Adjust your child's resemblance to parents") bar1 = gr.Slider(label="gamma", minimum=0, maximum=1, value=0.47) bar2 = gr.Slider(label="eta", minimum=0, maximum=1, value=0.4) bt_run = gr.Button("Run") gr.Markdown("""## Disclaimer This method is intended for academic research purposes only and is strictly prohibited for commercial use. Users are required to comply with all local laws and regulations when using this method.""") with gr.Column(): gr.Markdown("### Results") img3 = gr.Image(label="Generated child") with gr.Row(): img1_align = gr.Image(label="Father") img2_align = gr.Image(label="Mother") def run(father, mother, gamma, eta, age, gender): attributes = {'age': age, 'gender': gender, 'gamma': float(gamma), 'eta': float(eta)} img_F, img_M, img_C = synthesize_descendant(father, mother, attributes) return img_F, img_M, img_C bt_run.click(run, [img1, img2, bar1, bar2, age, gender], [img1_align, img2_align, img3]) block.launch(show_error=True)