Harsh-7300 commited on
Commit
719f10f
1 Parent(s): 78299c1

Upload 63 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. README.md +10 -1
  2. app.py +169 -0
  3. examples/basemodel.png +0 -0
  4. examples/garment1.jpg +0 -0
  5. examples/garment1.png +0 -0
  6. examples/garment2.jpg +0 -0
  7. examples/garment2.png +0 -0
  8. examples/garment3.png +0 -0
  9. examples/result1.png +0 -0
  10. examples/result2.png +0 -0
  11. examples/result3.png +0 -0
  12. garments/bottom1.png +0 -0
  13. garments/bottom2.PNG +0 -0
  14. garments/bottom3.JPG +0 -0
  15. garments/bottom4.PNG +0 -0
  16. garments/bottom5.png +0 -0
  17. garments/dress1.png +0 -0
  18. garments/dress2.png +0 -0
  19. garments/top111.png +0 -0
  20. garments/top222.JPG +0 -0
  21. garments/top3.JPG +0 -0
  22. garments/top333.png +0 -0
  23. garments/top4.png +0 -0
  24. garments/top5.png +0 -0
  25. models/eva/Eva_0.png +0 -0
  26. models/eva/Eva_1.png +0 -0
  27. models/rouyan_new/0/densepose.png +0 -0
  28. models/rouyan_new/0/humanmask.png +0 -0
  29. models/rouyan_new/0/initmask.png +0 -0
  30. models/rouyan_new/0/model.png +0 -0
  31. models/rouyan_new/1/a +1 -0
  32. models/rouyan_new/1/humanmask.png +0 -0
  33. models/rouyan_new/1/initmask.png +0 -0
  34. models/rouyan_new/1/mdensepose.png +0 -0
  35. models/rouyan_new/1/model.png +0 -0
  36. models/rouyan_new/2/a +1 -0
  37. models/rouyan_new/2/densepose.png +0 -0
  38. models/rouyan_new/2/humanmask.png +0 -0
  39. models/rouyan_new/2/initmask.png +0 -0
  40. models/rouyan_new/2/model.png +0 -0
  41. models/rouyan_new/Rouyan_0.png +0 -0
  42. models/rouyan_new/Rouyan_1.png +0 -0
  43. models/rouyan_new/Rouyan_2.png +0 -0
  44. models/simon_online/Simon_0.png +0 -0
  45. models/simon_online/Simon_1.png +0 -0
  46. models/simon_online/a +1 -0
  47. models/xiaoxuan/a +1 -0
  48. models/xiaoxuan/model.png +0 -0
  49. models/xiaoxuan_online/Xuanxuan_0.png +0 -0
  50. models/xiaoxuan_online/Xuanxuan_1.png +0 -0
README.md CHANGED
@@ -1,3 +1,12 @@
1
  ---
2
- license: mit
 
 
 
 
 
 
 
 
3
  ---
 
 
1
  ---
2
+ title: OutfitAnyone
3
+ emoji: 🏢
4
+ colorFrom: red
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 4.8.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: cc-by-nc-4.0
11
  ---
12
+
app.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import cv2 as cv
3
+ import numpy as np
4
+ import json
5
+ import random
6
+ from PIL import Image, ImageDraw, ImageFont
7
+ import asyncio
8
+ import socket
9
+ import requests
10
+ import base64
11
+ import gradio as gr
12
+ # from IPython import embed
13
+
14
+
15
+ machine_number = 0
16
+ model = os.path.join(os.path.dirname(__file__), "models/eva/Eva_0.png")
17
+
18
+ MODEL_MAP = {
19
+ "AI Model Rouyan_0": 'models/rouyan_new/Rouyan_0.png',
20
+ "AI Model Rouyan_1": 'models/rouyan_new/Rouyan_1.png',
21
+ "AI Model Rouyan_2": 'models/rouyan_new/Rouyan_2.png',
22
+ "AI Model Eva_0": 'models/eva/Eva_0.png',
23
+ "AI Model Eva_1": 'models/eva/Eva_1.png',
24
+ "AI Model Simon_0": 'models/simon_online/Simon_0.png',
25
+ "AI Model Simon_1": 'models/simon_online/Simon_1.png',
26
+ "AI Model Xuanxuan_0": 'models/xiaoxuan_online/Xuanxuan_0.png',
27
+ "AI Model Xuanxuan_1": 'models/xiaoxuan_online/Xuanxuan_1.png',
28
+ "AI Model Xuanxuan_2": 'models/xiaoxuan_online/Xuanxuan_2.png',
29
+ "AI Model Yaqi_0": 'models/yaqi/Yaqi_0.png',
30
+ "AI Model Yaqi_1": 'models/yaqi/Yaqi_1.png',
31
+ "AI Model Yaqi_2": 'models/yaqi/Yaqi_2.png',
32
+ "AI Model Yaqi_3": 'models/yaqi/Yaqi_3.png',
33
+ "AI Model Yifeng_0": 'models/yifeng_online/Yifeng_0.png',
34
+ "AI Model Yifeng_1": 'models/yifeng_online/Yifeng_1.png',
35
+ "AI Model Yifeng_2": 'models/yifeng_online/Yifeng_2.png',
36
+ "AI Model Yifeng_3": 'models/yifeng_online/Yifeng_3.png',
37
+ }
38
+
39
+ def add_waterprint(img: cv.Mat) -> cv.Mat:
40
+ h, w, _ = img.shape
41
+ img = cv.putText(img, 'Powered by OutfitAnyone', (int(0.3*w), h-20), cv.FONT_HERSHEY_PLAIN, 2, (128, 128, 128), 2, cv.LINE_AA)
42
+ return img
43
+
44
+
45
+ def get_tryon_result(model_name: str, garment1: cv.Mat, garment2: cv.Mat | None, seed: int = 1234) -> cv.Mat:
46
+ #model_name = "AI Model " + model_name.split("\\")[-1].split(".")[0] # windows
47
+ model_name = "AI Model " + model_name.split("/")[-1].split(".")[0] # linux
48
+ print(model_name)
49
+ encoded_garment1 = cv.imencode('.jpg', garment1)[1].tobytes()
50
+ encoded_garment1 = base64.b64encode(encoded_garment1).decode('utf-8')
51
+
52
+ if garment2 is not None:
53
+ encoded_garment2 = cv.imencode('.jpg', garment2)[1].tobytes()
54
+ encoded_garment2 = base64.b64encode(encoded_garment2).decode('utf-8')
55
+ else:
56
+ encoded_garment2 = ''
57
+
58
+ host_ip = socket.gethostbyname(socket.gethostname())
59
+ url = f"https://{host_ip}:192.168.115.27"
60
+ headers = {'Content-Type': 'application/json'}
61
+ seed = random.randint(0, 1222222222)
62
+ data = {
63
+ "garment1": encoded_garment1,
64
+ "garment2": encoded_garment2,
65
+ "model_name": model_name,
66
+ "seed": seed
67
+ }
68
+ response = requests.post(url, headers=headers, data=json.dumps(data))
69
+ print("response code", response.status_code)
70
+ if response.status_code == 200:
71
+ result = response.json()
72
+ result = base64.b64decode(result['images'][0])
73
+ result_np = np.frombuffer(result, np.uint8)
74
+ result_img = cv.imdecode(result_np, cv.IMREAD_UNCHANGED)
75
+ else:
76
+ print('server error!')
77
+
78
+
79
+ final_img = add_waterprint(result_img)
80
+
81
+ return final_img
82
+
83
+ '''height, width = 500, 500 # Adjust dimensions as needed
84
+ channels = 3 # 3 for RGB, 1 for grayscale
85
+ result_img = np.zeros((height, width, channels), dtype=np.uint8)
86
+ result_img[:] = (255, 0, 0) # Set the image to solid blue color
87
+
88
+ # final_img = add_waterprint(result_img)
89
+ return result_img'''
90
+
91
+
92
+
93
+ with gr.Blocks(css = ".output-image, .input-image, .image-preview {height: 400px !important} ") as demo:
94
+ # gr.Markdown("# Outfit Anyone v0.9")
95
+ gr.HTML(
96
+ """
97
+ <div>
98
+ <h1 >Outfit Anyone: Ultra-high quality virtual try-on for Any Clothing and Any Person</h1>
99
+ </div>
100
+ """)
101
+ with gr.Row():
102
+ with gr.Column():
103
+ init_image = gr.Image(type="filepath", label="model", value=model)
104
+ example = gr.Examples(inputs=init_image,
105
+ examples_per_page=4,
106
+ examples=[os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_0')),
107
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_2')),
108
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Eva_0')),
109
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_1')),
110
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Eva_1')),
111
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_0')),
112
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Xuanxuan_0')),
113
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Xuanxuan_2')),
114
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yaqi_1')),
115
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_0')),
116
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_3')),
117
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_1')),
118
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_2')),
119
+ os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yaqi_0')),
120
+ ])
121
+ with gr.Column():
122
+ gr.HTML(
123
+ """
124
+ <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
125
+ <div>
126
+ <h3>Models are fixed and cannot be uploaded or modified; we only support users uploading their own garments.</h3>
127
+ <h4 style="margin: 0;">For a one-piece dress or coat, you only need to upload the image to the 'top garment' section and leave the 'lower garment' section empty.</h4>
128
+ </div>
129
+ </div>
130
+ """)
131
+ with gr.Row():
132
+ garment_top = gr.Image(type="numpy", label="top garment")
133
+ garment_down = gr.Image(type="numpy", label="lower garment")
134
+
135
+ run_button = gr.Button(value="Run")
136
+ with gr.Column():
137
+ gallery = gr.Image()
138
+
139
+ run_button.click(fn=get_tryon_result,
140
+ inputs=[
141
+ init_image,
142
+ garment_top,
143
+ garment_down,
144
+ ],
145
+ outputs=[gallery],
146
+ show_progress=True,
147
+ concurrency_limit=2)
148
+
149
+ # Examples
150
+ gr.Markdown("## Examples")
151
+ with gr.Row():
152
+ reference_image1 = gr.Image(label="model", scale=1, value="examples/basemodel.png")
153
+ reference_image2 = gr.Image(label="garment", scale=1, value="examples/garment1.jpg")
154
+ reference_image3 = gr.Image(label="result", scale=1, value="examples/result1.png")
155
+ gr.Examples(
156
+ examples=[
157
+ ["examples/basemodel.png", "examples/garment1.png", "examples/result1.png"],
158
+ ["examples/basemodel.png", "examples/garment2.png", "examples/result2.png"],
159
+ ["examples/basemodel.png", "examples/garment3.png", "examples/result3.png"],
160
+ ],
161
+ inputs=[reference_image1, reference_image2, reference_image3],
162
+ label=None,
163
+ )
164
+
165
+ if __name__ == "__main__":
166
+ ip = requests.get('http://ifconfig.me/ip', timeout=1).text.strip()
167
+ print("ip address alibaba", ip)
168
+ demo.queue(max_size=10)
169
+ demo.launch()
examples/basemodel.png ADDED
examples/garment1.jpg ADDED
examples/garment1.png ADDED
examples/garment2.jpg ADDED
examples/garment2.png ADDED
examples/garment3.png ADDED
examples/result1.png ADDED
examples/result2.png ADDED
examples/result3.png ADDED
garments/bottom1.png ADDED
garments/bottom2.PNG ADDED
garments/bottom3.JPG ADDED
garments/bottom4.PNG ADDED
garments/bottom5.png ADDED
garments/dress1.png ADDED
garments/dress2.png ADDED
garments/top111.png ADDED
garments/top222.JPG ADDED
garments/top3.JPG ADDED
garments/top333.png ADDED
garments/top4.png ADDED
garments/top5.png ADDED
models/eva/Eva_0.png ADDED
models/eva/Eva_1.png ADDED
models/rouyan_new/0/densepose.png ADDED
models/rouyan_new/0/humanmask.png ADDED
models/rouyan_new/0/initmask.png ADDED
models/rouyan_new/0/model.png ADDED
models/rouyan_new/1/a ADDED
@@ -0,0 +1 @@
 
 
1
+
models/rouyan_new/1/humanmask.png ADDED
models/rouyan_new/1/initmask.png ADDED
models/rouyan_new/1/mdensepose.png ADDED
models/rouyan_new/1/model.png ADDED
models/rouyan_new/2/a ADDED
@@ -0,0 +1 @@
 
 
1
+
models/rouyan_new/2/densepose.png ADDED
models/rouyan_new/2/humanmask.png ADDED
models/rouyan_new/2/initmask.png ADDED
models/rouyan_new/2/model.png ADDED
models/rouyan_new/Rouyan_0.png ADDED
models/rouyan_new/Rouyan_1.png ADDED
models/rouyan_new/Rouyan_2.png ADDED
models/simon_online/Simon_0.png ADDED
models/simon_online/Simon_1.png ADDED
models/simon_online/a ADDED
@@ -0,0 +1 @@
 
 
1
+
models/xiaoxuan/a ADDED
@@ -0,0 +1 @@
 
 
1
+
models/xiaoxuan/model.png ADDED
models/xiaoxuan_online/Xuanxuan_0.png ADDED
models/xiaoxuan_online/Xuanxuan_1.png ADDED