|
|
import gradio as gr |
|
|
from diffusers import DiffusionPipeline |
|
|
import torch |
|
|
import os |
|
|
|
|
|
token = os.getenv("HF_TOKEN") |
|
|
|
|
|
pipe = DiffusionPipeline.from_pretrained( |
|
|
"Kotiko-ua/tryondiffusion-model", |
|
|
use_auth_token=token |
|
|
) |
|
|
|
|
|
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu") |
|
|
|
|
|
def try_on(person_img, cloth_img): |
|
|
|
|
|
prompt = f"A photo of this person wearing the clothes shown." |
|
|
images = pipe(prompt, image=[person_img, cloth_img]).images |
|
|
return images[0] |
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=try_on, |
|
|
inputs=[gr.Image(label="Person"), gr.Image(label="Clothing")], |
|
|
outputs=gr.Image(label="Result"), |
|
|
title="Virtual Try-On (TryOnDiffusion)", |
|
|
description="Upload a full-body photo and a clothing item to see a virtual try-on result." |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|