File size: 1,336 Bytes
5edd223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
__author__ = 'Ahmad Abdulnasir Shuaib <[email protected]>'
__homepage__ = https://ahmadabdulnasir.com.ng
__copyright__ = 'Copyright (c) 2024, salafi'
__version__ = "0.01t"
"""
import gradio as gr

from PIL import Image

def change_clothes(person_img, shirt_img=None, trouser_img=None):
    person = Image.open(person_img).convert("RGBA")  # Ensure person image has an alpha channel
    if shirt_img:
        shirt = Image.open(shirt_img).convert("RGBA").resize((person.width, int(person.height * 0.5)))
        person.paste(shirt, (0, 0), shirt)  # Paste shirt with transparency
    if trouser_img:
        trouser = Image.open(trouser_img).convert("RGBA").resize((person.width, int(person.height * 0.5)))
        person.paste(trouser, (0, int(person.height * 0.5)), trouser)  # Paste trouser with transparency
    return person

def run():
    iface = gr.Interface(
    fn=change_clothes,
    inputs=[
        gr.Image(type="filepath", label="Upload Person Image"),
        gr.Image(type="filepath", label="Upload Shirt Image", ),
        gr.Image(type="filepath", label="Upload Trouser Image", ),
    ],
        outputs="image",
        title="Clothes Change Interface"
    )

    iface.launch(show_error=True )


def boot():
    run()

if __name__ == "__main__":
    boot()