|
import torch |
|
from diffusers import StableDiffusionPipeline |
|
import gradio as gr |
|
from PIL import Image |
|
|
|
|
|
model_id = "ares1123/virtual-dress-try-on" |
|
pipeline = StableDiffusionPipeline.from_pretrained(model_id) |
|
pipeline.to("cuda" if torch.cuda.is_available() else "cpu") |
|
|
|
def virtual_try_on(image, clothing_image): |
|
|
|
width, height = image.size |
|
|
|
|
|
width = (width // 8) * 8 |
|
height = (height // 8) * 8 |
|
|
|
|
|
image = image.resize((width, height)) |
|
clothing_image = clothing_image.resize((width, height)) |
|
|
|
|
|
prompt = "A person wearing new clothes" |
|
|
|
|
|
result = pipeline(prompt=prompt, image=image, conditioning_image=clothing_image) |
|
try_on_image = result.images[0] |
|
|
|
return try_on_image |
|
|
|
|
|
interface = gr.Interface( |
|
fn=virtual_try_on, |
|
inputs=[gr.Image(type="pil", label="User Image"), |
|
gr.Image(type="pil", label="Clothing Image")], |
|
outputs=gr.Image(type="pil"), |
|
title="Virtual Dress Try-On", |
|
description="Upload an image of yourself and a clothing image to try it on virtually!" |
|
) |
|
|
|
|
|
interface.launch(share=True) |
|
|