hayalsaatim commited on
Commit
6202025
·
verified ·
1 Parent(s): 5a62cdc

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +6 -8
  2. app.py +65 -0
  3. requirements.txt +7 -0
README.md CHANGED
@@ -1,12 +1,10 @@
1
  ---
2
- title: Res
3
- emoji: 📉
4
- colorFrom: red
5
- colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 5.47.0
8
  app_file: app.py
9
  pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Virtual Try-On
3
+ emoji: "👕"
4
+ colorFrom: pink
5
+ colorTo: purple
6
  sdk: gradio
7
+ sdk_version: "3.37"
8
  app_file: app.py
9
  pinned: false
10
+ ---
 
 
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ import torch
4
+ from diffusers import StableDiffusionInpaintPipeline
5
+
6
+ device = "cpu"
7
+
8
+ MODEL_ID = "runwayml/stable-diffusion-inpainting"
9
+ pipe = StableDiffusionInpaintPipeline.from_pretrained(
10
+ MODEL_ID,
11
+ torch_dtype=torch.float32
12
+ )
13
+ pipe = pipe.to(device)
14
+
15
+ def tryon(person_img, cloth_img, prompt="A photo of the person wearing the selected clothing, realistic, photorealistic"):
16
+ if person_img is None or cloth_img is None:
17
+ return None
18
+
19
+ person = person_img.convert("RGB")
20
+ cloth = cloth_img.convert("RGBA")
21
+
22
+ pw, ph = person.size
23
+ cw, ch = cloth.size
24
+
25
+ scale = 0.6 * pw / cw
26
+ new_w = max(10, int(cw * scale))
27
+ new_h = max(10, int(ch * scale))
28
+ cloth_resized = cloth.resize((new_w, new_h), Image.LANCZOS)
29
+
30
+ alpha = cloth_resized.split()[-1]
31
+ mask = Image.new("L", (pw, ph), 0)
32
+
33
+ x = int((pw - new_w) / 2)
34
+ y = int(ph * 0.18)
35
+ mask.paste(alpha, (x, y))
36
+
37
+ composite = person.copy()
38
+ composite.paste(cloth_resized, (x, y), cloth_resized)
39
+
40
+ result = pipe(
41
+ prompt=prompt,
42
+ image=composite,
43
+ mask_image=mask,
44
+ guidance_scale=7.5,
45
+ num_inference_steps=30
46
+ ).images[0]
47
+
48
+ return result
49
+
50
+ with gr.Blocks() as demo:
51
+ gr.Markdown("## 👕 AI Kıyafet Giydirme\nFotoğrafını ve kıyafet resmini yükle, sonucu gör!")
52
+
53
+ with gr.Row():
54
+ with gr.Column():
55
+ person_in = gr.Image(type="pil", label="Kullanıcı Fotoğrafı")
56
+ cloth_in = gr.Image(type="pil", label="Kıyafet Fotoğrafı (PNG, şeffaf arka plan)")
57
+ prompt_in = gr.Textbox(label="Prompt (opsiyonel)", placeholder="Açıklama ekleyebilirsin...")
58
+ btn = gr.Button("Giydir")
59
+ with gr.Column():
60
+ out = gr.Image(type="pil", label="Sonuç")
61
+
62
+ btn.click(fn=tryon, inputs=[person_in, cloth_in, prompt_in], outputs=out)
63
+
64
+ if __name__ == "__main__":
65
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio==3.37
2
+ torch
3
+ diffusers
4
+ transformers
5
+ accelerate
6
+ safetensors
7
+ pillow