File size: 4,577 Bytes
d3fbdbe
 
 
39cc549
 
 
d3fbdbe
 
 
 
 
dc2b5b8
d3fbdbe
 
 
3c3086b
d3fbdbe
 
3c3086b
d3fbdbe
39cc549
 
 
 
 
 
 
d3fbdbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
063376b
d3fbdbe
 
 
 
 
 
 
 
 
 
 
d1578b9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import gradio as gr 
import os
from PIL import Image
from ip_adapter_openpose import generate as generate_ip_adapter_openpose
from ip_adapter_inpainting import generate as generate_ip_adapter_inpainting
from adapter_model import MODEL

human = os.path.join(os.path.dirname(__file__), "humans/manken3.jpg")


def get_tryon_result(human_path, top_path, down_path):
    human_img = Image.open(human_path).convert("RGB").resize((512,768))
    # UPPER BODY 4 , LOWER BODY 6
    if top_path:
        segment_id = 4
        clothes_img = Image.open(top_path).convert("RGB").resize((512,768))
    elif down_path:
        segment_id = 6
        clothes_img = Image.open(down_path).convert("RGB").resize((512,768))
    
    img_openpose_gen = generate_ip_adapter_openpose(human_img, clothes_img)
    final_gen = generate_ip_adapter_inpainting(img_openpose_gen,
                                                human_img,
                                                clothes_img,
                                                segment_id
                                                )
    return final_gen


with gr.Blocks(css=".output-image, .input-image, .image-preview {height: 400px !important} ") as demo:
    gr.HTML(
        """
        <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
        <a href="https://github.com/altayavci" style="margin-right: 20px; text-decoration: none; display: flex; align-items: center;">
        </a>
        <div>
            <h1 >Clothes Changer: SuperAppLabs Clothes Tryon Case Study</h1>
            <h4 >v0.1</h4>
            <h5 style="margin: 0;">Altay Avcı</h5>
        </div>
        </div>
        """)

    with gr.Column():
        gr.HTML(
                """
                        <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
                        <div>
                            <h3>TOP OR BOTTOM. NOT BOTH</h3>
                        </div>
                        </div>
                        """)
        
        with gr.Row():
            top = gr.Image(sources='upload', type="filepath", label="TOP")
            example_top = gr.Examples(inputs=top,
                                      examples_per_page=3,
                                      examples=[os.path.join(os.path.dirname(__file__), "clothes/kıyafet.jpg"),
                                                os.path.join(os.path.dirname(__file__), "clothes/kıyafet1.jpg"),
                                                os.path.join(os.path.dirname(__file__), "clothes/kıyafet3.jpeg"),
                                                            ])
                
            with gr.Column():
                down = gr.Image(sources='upload', type="filepath", label="DOWN")
                example_down = gr.Examples(inputs=down,
                                           examples_per_page=3,
                                           examples=[
                                                os.path.join(os.path.dirname(__file__), "clothes/garments_bottom1.png"),
                                                os.path.join(os.path.dirname(__file__), "clothes/indir (3).png"),
                                                os.path.join(os.path.dirname(__file__), "clothes/WhatsApp Image 2024-01-02 at 01.24.44.jpeg")
                                                            ])
                
        with gr.Row():      
                init_image = gr.Image(sources='clipboard', type="filepath", label="HUMAN", value=human)              
                example_models = gr.Examples(inputs=init_image,
                                             examples_per_page=2,
                                             examples=[os.path.join(os.path.dirname(__file__), "humans/manken3.jpg"),
                                                       os.path.join(os.path.dirname(__file__), "humans/manken2.jpg")
                                                      ])
        with gr.Column():
            run_button = gr.Button(value="Run") 
            gallery = gr.Image() #width=512, height=768
            run_button.click(fn=get_tryon_result, 
                             inputs=[
                                  init_image,
                                  top,
                                  down,
                                  ],
                                  outputs=[gallery]
                                  )               
    
if __name__ == "__main__":
    demo.queue(max_size=10)
    demo.launch(share=True)