Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,50 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
-
import shutil
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
Image.new("RGB", (768, 1024), (200, 200, 200)).save(dummy_image_path)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
output_path = RESULT_DIR / "output.png"
|
| 23 |
-
shutil.copy(dummy_image_path, output_path)
|
| 24 |
-
return output_path
|
| 25 |
|
|
|
|
| 26 |
with gr.Blocks() as demo:
|
| 27 |
-
gr.Markdown(
|
| 28 |
-
"""# V-Try AI Try-On
|
| 29 |
-
Upload a shirt or outfit to see the try-on result. Powered by IDM-VTON (dummy)."""
|
| 30 |
-
)
|
| 31 |
with gr.Row():
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
demo.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
+
# ======= Dummy try-on function =======
|
| 7 |
+
# Replace this with your IDM-VTON model call
|
| 8 |
+
def vton_tryon(human_img, garment_img, auto_mask=True, auto_resize=True, description=""):
|
| 9 |
+
"""
|
| 10 |
+
human_img: PIL.Image
|
| 11 |
+
garment_img: PIL.Image
|
| 12 |
+
Returns: PIL.Image of human with garment overlay (dummy)
|
| 13 |
+
"""
|
| 14 |
+
# Convert to OpenCV format
|
| 15 |
+
human = cv2.cvtColor(np.array(human_img), cv2.COLOR_RGB2BGR)
|
| 16 |
+
garment = cv2.cvtColor(np.array(garment_img), cv2.COLOR_RGB2BGR)
|
| 17 |
|
| 18 |
+
# Resize garment to human size if auto_resize
|
| 19 |
+
if auto_resize:
|
| 20 |
+
garment = cv2.resize(garment, (human.shape[1], human.shape[0]))
|
| 21 |
|
| 22 |
+
# Dummy overlay: just blend human + garment
|
| 23 |
+
output = cv2.addWeighted(human, 0.7, garment, 0.3, 0)
|
|
|
|
| 24 |
|
| 25 |
+
# Convert back to PIL
|
| 26 |
+
output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB)
|
| 27 |
+
return Image.fromarray(output)
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
# ======= Gradio Interface =======
|
| 30 |
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("## IDM-VTON 👕👔👚 Virtual Try-On with Gradio")
|
|
|
|
|
|
|
|
|
|
| 32 |
with gr.Row():
|
| 33 |
+
with gr.Column():
|
| 34 |
+
human_img = gr.Image(label="Upload Human Image", type="pil")
|
| 35 |
+
auto_mask = gr.Checkbox(label="Use Auto-Mask", value=True)
|
| 36 |
+
auto_resize = gr.Checkbox(label="Auto Crop & Resize", value=True)
|
| 37 |
+
with gr.Column():
|
| 38 |
+
garment_img = gr.Image(label="Upload Garment Image", type="pil")
|
| 39 |
+
description = gr.Textbox(label="Garment Description", placeholder="Short Sleeve Tee, etc.")
|
| 40 |
+
|
| 41 |
+
tryon_btn = gr.Button("Generate Try-On")
|
| 42 |
+
output_img = gr.Image(label="Try-On Result")
|
| 43 |
+
|
| 44 |
+
tryon_btn.click(
|
| 45 |
+
fn=vton_tryon,
|
| 46 |
+
inputs=[human_img, garment_img, auto_mask, auto_resize, description],
|
| 47 |
+
outputs=output_img
|
| 48 |
+
)
|
| 49 |
|
| 50 |
+
demo.launch()
|