fanboyd13 commited on
Commit
d2f7be4
·
verified ·
1 Parent(s): 49d37b3

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -26
app.py CHANGED
@@ -1,36 +1,50 @@
1
  import gradio as gr
2
- from pathlib import Path
 
3
  from PIL import Image
4
- import shutil
5
 
6
- BASE_DIR = Path(__file__).parent
7
- UPLOAD_DIR = BASE_DIR / "uploads"
8
- RESULT_DIR = BASE_DIR / "result"
9
- DATA_DIR = BASE_DIR / "DATA_DIR"
 
 
 
 
 
 
 
10
 
11
- UPLOAD_DIR.mkdir(exist_ok=True)
12
- RESULT_DIR.mkdir(exist_ok=True)
13
- DATA_DIR.mkdir(exist_ok=True)
14
 
15
- dummy_image_path = DATA_DIR / "dummy_image.png"
16
- if not dummy_image_path.exists():
17
- Image.new("RGB", (768, 1024), (200, 200, 200)).save(dummy_image_path)
18
 
19
- def run_tryon(image: Image.Image):
20
- input_path = UPLOAD_DIR / "input.png"
21
- image.save(input_path)
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
- input_img = gr.Image(type="pil", label="Upload Shirt/Outfit")
33
- output_img = gr.Image(type="pil", label="Try-On Result")
34
- input_img.change(fn=run_tryon, inputs=input_img, outputs=output_img)
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
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()