Spaces:
Running
Running
Upload 3 files
Browse files- README.md +21 -7
- app.py +94 -0
- requirements.txt +4 -0
README.md
CHANGED
|
@@ -1,12 +1,26 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
-
pinned:
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: AI Virtual Try-On
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.1
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
+
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# π AI Virtual Try-On
|
| 14 |
+
|
| 15 |
+
Upload your photo and a clothing item β AI shows you how it looks on you!
|
| 16 |
+
|
| 17 |
+
## How to use
|
| 18 |
+
1. Upload your full-body photo
|
| 19 |
+
2. Upload a clothing product image
|
| 20 |
+
3. Click Generate Try-On!
|
| 21 |
+
|
| 22 |
+
## Tech Stack
|
| 23 |
+
- **Frontend**: React.js
|
| 24 |
+
- **AI Model**: IDM-VTON (Diffusion Model)
|
| 25 |
+
- **Garment Detection**: Claude Vision API
|
| 26 |
+
- **Deployment**: Hugging Face Spaces
|
app.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_client import Client, handle_file
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import tempfile, os, time
|
| 5 |
+
|
| 6 |
+
# ββ This runs on YOUR Hugging Face Space ββββββββββββββββββββββββββββββββββ
|
| 7 |
+
# Users call YOUR space β YOUR space calls IDM-VTON internally
|
| 8 |
+
# No rate limits for your users!
|
| 9 |
+
|
| 10 |
+
def virtual_tryon(person_image, cloth_image, garment_description, steps, seed):
|
| 11 |
+
if person_image is None or cloth_image is None:
|
| 12 |
+
return None, "β οΈ Please upload both images!"
|
| 13 |
+
|
| 14 |
+
try:
|
| 15 |
+
# Save PIL images to temp files
|
| 16 |
+
p_path = tempfile.mktemp(suffix=".jpg")
|
| 17 |
+
c_path = tempfile.mktemp(suffix=".jpg")
|
| 18 |
+
person_image.save(p_path)
|
| 19 |
+
cloth_image.save(c_path)
|
| 20 |
+
|
| 21 |
+
# Call IDM-VTON
|
| 22 |
+
client = Client("yisol/IDM-VTON")
|
| 23 |
+
|
| 24 |
+
start = time.time()
|
| 25 |
+
result = client.predict(
|
| 26 |
+
dict={
|
| 27 |
+
"background": handle_file(p_path),
|
| 28 |
+
"layers": [],
|
| 29 |
+
"composite": None
|
| 30 |
+
},
|
| 31 |
+
garm_img=handle_file(c_path),
|
| 32 |
+
garment_des=garment_description or "clothing item",
|
| 33 |
+
is_checked=True,
|
| 34 |
+
is_checked_crop=False,
|
| 35 |
+
denoise_steps=int(steps),
|
| 36 |
+
seed=int(seed),
|
| 37 |
+
api_name="/tryon"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
elapsed = time.time() - start
|
| 41 |
+
result_img = Image.open(result[0])
|
| 42 |
+
|
| 43 |
+
# Cleanup temp files
|
| 44 |
+
os.remove(p_path)
|
| 45 |
+
os.remove(c_path)
|
| 46 |
+
|
| 47 |
+
return result_img, f"β
Done in {elapsed:.1f}s!"
|
| 48 |
+
|
| 49 |
+
except Exception as e:
|
| 50 |
+
return None, f"β Error: {str(e)}"
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
# ββ Gradio UI βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 54 |
+
with gr.Blocks(title="AI Virtual Try-On", theme=gr.themes.Soft()) as demo:
|
| 55 |
+
|
| 56 |
+
gr.Markdown("""
|
| 57 |
+
# π AI Virtual Try-On
|
| 58 |
+
### Upload your photo + clothing β See how it looks on you!
|
| 59 |
+
*Powered by IDM-VTON Diffusion Model*
|
| 60 |
+
""")
|
| 61 |
+
|
| 62 |
+
with gr.Row():
|
| 63 |
+
person_input = gr.Image(label="π· Your Photo", type="pil", height=400)
|
| 64 |
+
cloth_input = gr.Image(label="π Clothing Image", type="pil", height=400)
|
| 65 |
+
result_output = gr.Image(label="β¨ Try-On Result", type="pil", height=400)
|
| 66 |
+
|
| 67 |
+
with gr.Row():
|
| 68 |
+
desc = gr.Textbox(
|
| 69 |
+
label="Garment Description (optional)",
|
| 70 |
+
placeholder="e.g. blue floral summer dress",
|
| 71 |
+
scale=3
|
| 72 |
+
)
|
| 73 |
+
steps = gr.Slider(15, 40, value=30, step=1, label="Quality Steps")
|
| 74 |
+
seed = gr.Number(value=42, label="Seed", precision=0)
|
| 75 |
+
|
| 76 |
+
with gr.Row():
|
| 77 |
+
run_btn = gr.Button("π Generate Try-On!", variant="primary", size="lg")
|
| 78 |
+
status = gr.Textbox(label="Status", interactive=False, scale=2)
|
| 79 |
+
|
| 80 |
+
run_btn.click(
|
| 81 |
+
fn=virtual_tryon,
|
| 82 |
+
inputs=[person_input, cloth_input, desc, steps, seed],
|
| 83 |
+
outputs=[result_output, status]
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
gr.Markdown("""
|
| 87 |
+
### π‘ Tips
|
| 88 |
+
- Use a **clear full-body photo** standing straight
|
| 89 |
+
- Use **product photos** with white background for clothing
|
| 90 |
+
- For dresses, describe it: *"blue floral midi dress"*
|
| 91 |
+
- Increase steps to **35-40** for best quality
|
| 92 |
+
""")
|
| 93 |
+
|
| 94 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.44.1
|
| 2 |
+
gradio_client==0.8.1
|
| 3 |
+
Pillow>=10.0.0
|
| 4 |
+
requests
|