haizad commited on
Commit
d2bc90c
·
1 Parent(s): 8596e2c

Add project files with proper Git LFS tracking for binary files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.jpg filter=lfs diff=lfs merge=lfs -text
37
+ *.png filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Environments
2
+ .env
3
+ .venv
4
+ env/
5
+ venv/
6
+ ENV/
7
+ env.bak/
8
+ venv.bak/
9
+
10
+ # Python cache
11
+ __pycache__/
12
+ *.py[cod]
13
+ *.pyo
14
+ *.pyd
15
+ .Python
16
+ # Byte-compiled / optimized / DLL files
17
+ *.pyc
18
+ *.pyo
19
+ *.pyd
20
+ # C extensions
21
+ *.so
22
+
23
+ # OS generated files
24
+ .DS_Store
README.md CHANGED
@@ -9,6 +9,16 @@ app_file: app.py
9
  pinned: false
10
  license: cc-by-nc-sa-4.0
11
  short_description: MCP Server of Virtual Try On
 
 
 
 
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
9
  pinned: false
10
  license: cc-by-nc-sa-4.0
11
  short_description: MCP Server of Virtual Try On
12
+ tags:
13
+ - mcp-server-track
14
+ - viton
15
+ - OOTDiffusion
16
  ---
17
 
18
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
19
+
20
+ # Virtual Try-On
21
+
22
+ Virtual try-on application powered by [OOTDiffusion](https://github.com/levihsu/OOTDiffusion) that allows users to virtually try on garments using AI. This project includes both a Gradio web interface and Model Context Protocol (MCP) server capabilities for seamless integration with other AI assistants
23
+
24
+ Developed by [Haizad](https://huggingface.co/haizad) & [Hazel](https://huggingface.co/hazxxel)
app.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from PIL import Image
4
+ import requests
5
+ import base64
6
+ import io
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+ example_path = os.path.join(os.path.dirname(__file__), 'examples')
12
+
13
+ def image_to_base64(image_path): # Remove 'self'
14
+ """Convert image file to base64 string"""
15
+ with open(image_path, "rb") as image_file:
16
+ return base64.b64encode(image_file.read()).decode()
17
+
18
+ def base64_to_image(base64_str, output_path): # Remove 'self'
19
+ """Convert base64 string to image file"""
20
+ image_data = base64.b64decode(base64_str)
21
+ image = Image.open(io.BytesIO(image_data))
22
+ image.save(output_path)
23
+ return image
24
+
25
+ def run_viton(model_image_path, garment_image_path,
26
+ n_steps=20, image_scale=2.0, seed=-1):
27
+ try:
28
+ api_url = os.environ.get("SERVER_URL")
29
+ print(f"Using API URL: {api_url}") # Add this to debug
30
+
31
+ # Convert images to base64 (remove 'self.')
32
+ model_b64 = image_to_base64(model_image_path)
33
+ garment_b64 = image_to_base64(garment_image_path)
34
+
35
+ # Prepare request
36
+ request_data = {
37
+ "model_image_base64": model_b64,
38
+ "garment_image_base64": garment_b64,
39
+ "n_samples": 1,
40
+ "n_steps": n_steps,
41
+ "image_scale": image_scale,
42
+ "seed": seed
43
+ }
44
+
45
+ # Send request
46
+ response = requests.post(f"{api_url}/viton",
47
+ json=request_data,
48
+ timeout=300)
49
+
50
+ print(f"Request sent to {api_url}/viton")
51
+ print(f"Response status code: {response.status_code}")
52
+
53
+ if response.status_code == 200:
54
+ result = response.json()
55
+ if result.get("error"):
56
+ print(f"Error: {result['error']}")
57
+ return []
58
+
59
+ generated_images = []
60
+ for i, img_b64 in enumerate(result.get("images_base64", [])):
61
+ output_path = f"ootd_output_{i}.png"
62
+ img = base64_to_image(img_b64, output_path) # Remove 'self.'
63
+ generated_images.append(img)
64
+
65
+ print(f"Successfully generated {len(generated_images)} images")
66
+ return generated_images
67
+ else:
68
+ print(f"Request failed with status code: {response.status_code}")
69
+ return [] # Fix: was missing 'return'
70
+
71
+ except Exception as e:
72
+ print(f"Exception occurred: {str(e)}") # Add this
73
+ return [] # Fix: should return list, not dict for gallery
74
+
75
+ block = gr.Blocks().queue()
76
+ default_model = os.path.join(example_path, 'model/model_8.png')
77
+ default_garment = os.path.join(example_path, 'garment/00055_00.jpg')
78
+ with block:
79
+ with gr.Row():
80
+ gr.Markdown("# Virtual Try-On")
81
+ with gr.Row():
82
+ with gr.Column():
83
+ vton_img = gr.Image(label="Model", sources=['upload', 'webcam'], type="filepath", height=384, value=default_model)
84
+ example = gr.Examples(
85
+ inputs=vton_img,
86
+ examples_per_page=5,
87
+ examples=[
88
+ os.path.join(example_path, 'model/model_8.png'),
89
+ os.path.join(example_path, 'model/model_2.png'),
90
+ os.path.join(example_path, 'model/model_7.png'),
91
+ os.path.join(example_path, 'model/model_4.png'),
92
+ os.path.join(example_path, 'model/model_5.png'),
93
+ ])
94
+ with gr.Column():
95
+ garm_img = gr.Image(label="Garment", sources=['upload', 'webcam'], type="filepath", height=384, value=default_garment)
96
+ example = gr.Examples(
97
+ inputs=garm_img,
98
+ examples_per_page=5,
99
+ examples=[
100
+ os.path.join(example_path, 'garment/00055_00.jpg'),
101
+ os.path.join(example_path, 'garment/07764_00.jpg'),
102
+ os.path.join(example_path, 'garment/03032_00.jpg'),
103
+ os.path.join(example_path, 'garment/048554_1.jpg'),
104
+ os.path.join(example_path, 'garment/049805_1.jpg'),
105
+ ])
106
+ with gr.Column():
107
+ result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", preview=True, scale=1)
108
+ with gr.Column():
109
+ run_button = gr.Button(value="Run")
110
+ n_steps = gr.Slider(label="Steps", minimum=20, maximum=40, value=20, step=1)
111
+ image_scale = gr.Slider(label="Guidance scale", minimum=1.0, maximum=5.0, value=2.0, step=0.1)
112
+ seed = gr.Slider(label="Seed", minimum=-1, maximum=2147483647, step=1, value=-1)
113
+
114
+ ips = [vton_img, garm_img, n_steps, image_scale, seed]
115
+ run_button.click(fn=run_viton, inputs=ips, outputs=result_gallery)
116
+
117
+ block.launch(server_name='0.0.0.0', server_port=7865, mcp_server=True)
examples/garment/00055_00.jpg ADDED

Git LFS Details

  • SHA256: c9c13719456663be040a63711d0ee92c6bac2e259017b072d396d874bdc367ad
  • Pointer size: 130 Bytes
  • Size of remote file: 94.8 kB
examples/garment/03032_00.jpg ADDED

Git LFS Details

  • SHA256: f129842d75d9cd347414710bdc148b3277abae85b17f44b71158fd5c8d641eed
  • Pointer size: 130 Bytes
  • Size of remote file: 84.1 kB
examples/garment/048554_1.jpg ADDED

Git LFS Details

  • SHA256: c278aab7f43222916a965be0f199a9adaffc6d78a953f5f89c4cd81594130024
  • Pointer size: 131 Bytes
  • Size of remote file: 135 kB
examples/garment/049805_1.jpg ADDED

Git LFS Details

  • SHA256: 2c8abd5b5f7afeda2eefc54a343f3b6dd5e6eab2416d165e985db2241f32a537
  • Pointer size: 131 Bytes
  • Size of remote file: 171 kB
examples/garment/07764_00.jpg ADDED

Git LFS Details

  • SHA256: de415f74ca7a8ecf2241c428f7d2c42360d0f6cb703e3d6db2622de230ce6d06
  • Pointer size: 130 Bytes
  • Size of remote file: 95.5 kB
examples/model/model_2.png ADDED

Git LFS Details

  • SHA256: bc54d510c78933f710a30c9a64ff37e85f56ac55df8f0f5b0798f5ed6ae41045
  • Pointer size: 131 Bytes
  • Size of remote file: 455 kB
examples/model/model_4.png ADDED

Git LFS Details

  • SHA256: 005b4ff0b4cb78e0e165330ea5f329e404df9d739c7728285590675b3b43dbf9
  • Pointer size: 131 Bytes
  • Size of remote file: 761 kB
examples/model/model_5.png ADDED

Git LFS Details

  • SHA256: 5faaea84635da215bd0819cf5ce65512ca1b742c39ee8fd67176b19e084ed872
  • Pointer size: 131 Bytes
  • Size of remote file: 638 kB
examples/model/model_7.png ADDED

Git LFS Details

  • SHA256: 583995b49ed1b40834822c9f3b87086b90d68a4c4fcbf6709f7cd1f42450ee56
  • Pointer size: 131 Bytes
  • Size of remote file: 817 kB
examples/model/model_8.png ADDED

Git LFS Details

  • SHA256: bf4f2064cc6efe6aa4b6bb503d6d2aadba4feff13b5784457ed7ddd63c1fc20f
  • Pointer size: 131 Bytes
  • Size of remote file: 589 kB
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ pillow==9.4.0
2
+ gradio[mcp]==5.33.0
3
+ requests==2.32.3
4
+ python-dotenv==1.1.0