| | import spaces |
| | import gradio as gr |
| | import subprocess |
| | from PIL import Image,ImageOps,ImageDraw,ImageFilter |
| | import json |
| | import os |
| | import time |
| |
|
| | from mp_utils import get_pixel_cordinate_list,extract_landmark,get_pixel_cordinate |
| | from glibvision.draw_utils import points_to_box,box_to_xy,plus_point |
| |
|
| | import numpy as np |
| | from glibvision.pil_utils import fill_points,create_color_image,draw_points,draw_box |
| |
|
| | from gradio_utils import save_image,save_buffer,clear_old_files ,read_file |
| |
|
| | from mediapipe_transform import process_landmark_transform_pil |
| |
|
| |
|
| | ''' |
| | innner_eyes_blur - inner eyes blur |
| | iris_mask_blur - final iris edge blur |
| | ''' |
| |
|
| |
|
| | def process_images(image,transform_target,innner_mouth,innner_eyes, |
| | color_matching,transparent_background,add_align_mouth,add_align_eyes,blur_size, |
| | progress=gr.Progress(track_tqdm=True)): |
| | clear_old_files() |
| | if image == None: |
| | raise gr.Error("Need Image") |
| | if transform_target == None: |
| | raise gr.Error("Need one more Target Image") |
| | |
| | result = process_landmark_transform_pil(image,transform_target,innner_mouth,innner_eyes, |
| | color_matching,transparent_background,add_align_mouth,add_align_eyes,blur_size) |
| |
|
| | return result |
| |
|
| |
|
| | css=""" |
| | #col-left { |
| | margin: 0 auto; |
| | max-width: 640px; |
| | } |
| | #col-right { |
| | margin: 0 auto; |
| | max-width: 640px; |
| | } |
| | .grid-container { |
| | display: flex; |
| | align-items: center; |
| | justify-content: center; |
| | gap:10px |
| | } |
| | |
| | .image { |
| | width: 128px; |
| | height: 128px; |
| | object-fit: cover; |
| | } |
| | |
| | .text { |
| | font-size: 16px; |
| | } |
| | """ |
| |
|
| | |
| |
|
| | def align_check_control(is_transparent): |
| | if is_transparent: |
| | return gr.Checkbox(visible=True),gr.Checkbox(visible=True) |
| | else: |
| | return gr.Checkbox(visible=False),gr.Checkbox(visible=False) |
| |
|
| | with gr.Blocks(css=css, elem_id="demo-container") as demo: |
| | with gr.Column(): |
| | gr.HTML(read_file("demo_header.html")) |
| | gr.HTML(read_file("demo_tools.html")) |
| | with gr.Row(): |
| | with gr.Column(): |
| | image = gr.Image(height=800,sources=['upload','clipboard'],image_mode='RGB',elem_id="image_upload", type="pil", label="Image") |
| | align_image = gr.Image(height=800,sources=['upload','clipboard'],image_mode='RGB',elem_id="image_align", type="pil", label="Align Target") |
| | |
| | with gr.Row(elem_id="prompt-container", equal_height=False): |
| | with gr.Row(): |
| | btn = gr.Button("Transform landmarks", elem_id="run_button",variant="primary") |
| | |
| | |
| | |
| | with gr.Accordion(label="Advanced Settings", open=True): |
| | with gr.Row( equal_height=True): |
| | innner_mouth = gr.Checkbox(label="Include inner-Mouth",value=True,info="Transform teeesh and tongue") |
| | innner_eyes = gr.Checkbox(label="Include inner Eyes",value=True,info="Transform Iris") |
| | with gr.Row( equal_height=True): |
| | color_matching = gr.Checkbox(label="color_matching",value=True,info="histgram color matching(not good,when mouth opened)") |
| | transparent_background = gr.Checkbox(label="transparent-background",value=False,info="no background picture") |
| | with gr.Row( equal_height=True): |
| | add_align_mouth = gr.Checkbox(label="Add Align Mouth",value=True,info="add align-mouth when transparent",visible=False) |
| | add_align_eyes = gr.Checkbox(label="Add Align Eyes",value=True,info="add align-eyes when transparent",visible=False) |
| | blur_size = gr.Slider(info="blur-size", |
| | label="Blur-Size", |
| | minimum=0, |
| | maximum=100, |
| | step=1, |
| | value=50) |
| |
|
| | |
| | with gr.Column(): |
| | result_image = gr.Image(height=760,label="Result", elem_id="output-animation",image_mode='RGBA') |
| | |
| | |
| | transparent_background.change(fn=align_check_control,inputs=[transparent_background],outputs=[add_align_mouth,add_align_eyes]) |
| | btn.click(fn=process_images, inputs=[image,align_image,innner_mouth,innner_eyes, |
| | color_matching,transparent_background,add_align_mouth,add_align_eyes,blur_size |
| | ],outputs=[result_image] ,api_name='infer') |
| | |
| | example_images = [ |
| | ["examples/02316230.jpg"], |
| | ["examples/00003245_00.jpg"], |
| | ["examples/00827009.jpg"], |
| | ["examples/00002062.jpg"], |
| | ["examples/00824008.jpg"], |
| | ["examples/00825000.jpg"], |
| | ["examples/00826007.jpg"], |
| | ["examples/00824006.jpg"], |
| | ["examples/00828003.jpg"], |
| | ["examples/01090260.jpg"], |
| | |
| | |
| | ["examples/00002200.jpg"], |
| | ["examples/00005259.jpg"], |
| | ["examples/00018022.jpg"], |
| | ["examples/img-above.jpg"], |
| | ["examples/00100265.jpg"], |
| | ["examples/02250075.jpg"], |
| | |
| | ] |
| | example1=gr.Examples( |
| | examples = example_images,label="Image", |
| | inputs=[image],examples_per_page=8 |
| | ) |
| | example2=gr.Examples( |
| | examples =example_images[::-1],label="Align Image", |
| | inputs=[align_image],examples_per_page=8 |
| | ) |
| | gr.HTML(read_file("demo_footer.html")) |
| |
|
| | if __name__ == "__main__": |
| | demo.launch() |
| |
|