#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ __author__ = 'Ahmad Abdulnasir Shuaib ' __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()