| import gradio as gr |
| from diffusers import StableDiffusionPipeline |
| import torch |
| import os |
|
|
|
|
| model_id = "lllyasviel/TryOnDiffusion" |
| token = os.getenv("HF_TOKEN") |
|
|
| pipe = StableDiffusionPipeline.from_pretrained( |
| model_id, |
| use_auth_token=token, |
| torch_dtype=torch.float16 |
| ) |
| 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() |
|
|