jaehyunshin commited on
Commit
bbb3e9a
1 Parent(s): 0e5a658

add garments

Browse files
app.py CHANGED
@@ -1,90 +1,100 @@
 
 
 
1
  import os
 
 
2
  import cv2
 
3
  import numpy as np
4
- import json
5
- import random
6
  from PIL import Image, ImageDraw, ImageFont
7
- import asyncio
8
 
9
- import requests
10
- import base64
11
- import gradio as gr
12
  # from IPython import embed
13
 
14
  machine_number = 0
15
  model = os.path.join(os.path.dirname(__file__), "models/eva/Eva_0.png")
16
 
17
  MODEL_MAP = {
18
- "AI Model Rouyan_0": 'models/rouyan_new/Rouyan_0.png',
19
- "AI Model Rouyan_1": 'models/rouyan_new/Rouyan_1.png',
20
- "AI Model Rouyan_2": 'models/rouyan_new/Rouyan_2.png',
21
- "AI Model Eva_0": 'models/eva/Eva_0.png',
22
- "AI Model Eva_1": 'models/eva/Eva_1.png',
23
- "AI Model Simon_0": 'models/simon_online/Simon_0.png',
24
- "AI Model Simon_1": 'models/simon_online/Simon_1.png',
25
- "AI Model Xuanxuan_0": 'models/xiaoxuan_online/Xuanxuan_0.png',
26
- "AI Model Xuanxuan_1": 'models/xiaoxuan_online/Xuanxuan_1.png',
27
- "AI Model Xuanxuan_2": 'models/xiaoxuan_online/Xuanxuan_2.png',
28
- "AI Model Yaqi_0": 'models/yaqi/Yaqi_0.png',
29
- "AI Model Yaqi_1": 'models/yaqi/Yaqi_1.png',
30
- "AI Model Yaqi_2": 'models/yaqi/Yaqi_2.png',
31
- "AI Model Yaqi_3": 'models/yaqi/Yaqi_3.png',
32
- "AI Model Yifeng_0": 'models/yifeng_online/Yifeng_0.png',
33
- "AI Model Yifeng_1": 'models/yifeng_online/Yifeng_1.png',
34
- "AI Model Yifeng_2": 'models/yifeng_online/Yifeng_2.png',
35
- "AI Model Yifeng_3": 'models/yifeng_online/Yifeng_3.png',
 
36
  }
37
 
38
- def add_waterprint(img):
39
 
 
40
  h, w, _ = img.shape
41
- img = cv2.putText(img, 'Powered by OutfitAnyone', (int(0.3*w), h-20), cv2.FONT_HERSHEY_PLAIN, 2, (128, 128, 128), 2, cv2.LINE_AA)
 
 
 
 
 
 
 
 
 
42
 
43
  return img
44
 
45
 
46
  def get_tryon_result(model_name, garment1, garment2, seed=1234):
47
-
48
  # model_name = "AI Model " + model_name.split("\\")[-1].split(".")[0] # windows
49
- model_name = "AI Model " + model_name.split("/")[-1].split(".")[0] # linux
50
  print(model_name)
51
 
52
- encoded_garment1 = cv2.imencode('.jpg', garment1)[1].tobytes()
53
- encoded_garment1 = base64.b64encode(encoded_garment1).decode('utf-8')
54
 
55
  if garment2 is not None:
56
- encoded_garment2 = cv2.imencode('.jpg', garment2)[1].tobytes()
57
- encoded_garment2 = base64.b64encode(encoded_garment2).decode('utf-8')
58
  else:
59
- encoded_garment2 = ''
60
 
61
- url = os.environ['OA_IP_ADDRESS']
62
- headers = {'Content-Type': 'application/json'}
63
  seed = random.randint(0, 1222222222)
64
  data = {
65
  "garment1": encoded_garment1,
66
  "garment2": encoded_garment2,
67
  "model_name": model_name,
68
- "seed": seed
69
  }
70
  response = requests.post(url, headers=headers, data=json.dumps(data))
71
  print("response code", response.status_code)
72
  if response.status_code == 200:
73
  result = response.json()
74
- result = base64.b64decode(result['images'][0])
75
  result_np = np.frombuffer(result, np.uint8)
76
  result_img = cv2.imdecode(result_np, cv2.IMREAD_UNCHANGED)
77
  else:
78
- print('server error!')
79
 
80
-
81
  final_img = add_waterprint(result_img)
82
 
83
  return final_img
84
 
85
 
86
-
87
- with gr.Blocks(css = ".output-image, .input-image, .image-preview {height: 400px !important} ") as demo:
 
88
  # gr.Markdown("# Outfit Anyone v0.9")
89
  gr.HTML(
90
  """
@@ -92,100 +102,153 @@ with gr.Blocks(css = ".output-image, .input-image, .image-preview {height: 400px
92
  <a href="https://github.com/HumanAIGC/OutfitAnyone" style="margin-right: 20px; text-decoration: none; display: flex; align-items: center;">
93
  </a>
94
  <div>
95
- <h1 >Outfit Anyone: Ultra-high quality virtual try-on for Any Clothing and Any Person</h1>
96
- <h4 >v0.9</h4>
97
- <h5 style="margin: 0;">If you like our project, please give us a star on Github to stay updated with the latest developments.</h5>
98
- <div style="display: flex; justify-content: center; align-items: center; text-align: center;>
99
- <a href="https://github.com/HumanAIGC/OutfitAnyone"><img src="https://img.shields.io/badge/Arxiv-0000.00000-red"></a>
100
- <a href='https://humanaigc.github.io/outfit-anyone/'><img src='https://img.shields.io/badge/Project_Page-OutfitAnyone-green' alt='Project Page'></a>
101
- <a href='https://github.com/HumanAIGC/OutfitAnyone'><img src='https://img.shields.io/badge/Github-Repo-blue'></a>
102
- </div>
103
  </div>
104
  </div>
105
- """)
 
106
  with gr.Row():
107
  with gr.Column():
108
- init_image = gr.Image(sources='clipboard', type="filepath", label="model", value=model)
109
- example = gr.Examples(inputs=init_image,
110
- examples_per_page=4,
111
- examples=[os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_0')),
112
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_2')),
113
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Eva_0')),
114
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_1')),
115
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Eva_1')),
116
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_0')),
117
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Xuanxuan_0')),
118
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Xuanxuan_2')),
119
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yaqi_1')),
120
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_0')),
121
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_3')),
122
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_1')),
123
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_2')),
124
- os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yaqi_0')),
125
- ])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  with gr.Column():
127
  gr.HTML(
128
  """
129
  <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
130
  <div>
131
- <h3>Models are fixed and cannot be uploaded or modified; we only support users uploading their own garments.</h3>
132
- <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>
133
  </div>
134
  </div>
135
- """)
 
136
  with gr.Row():
137
- garment_top = gr.Image(sources='upload', type="numpy", label="top garment")
138
- example_top = gr.Examples(inputs=garment_top,
139
- examples_per_page=5,
140
- examples=[os.path.join(os.path.dirname(__file__), "garments/top222.JPG"),
141
- os.path.join(os.path.dirname(__file__), "garments/top5.png"),
142
- os.path.join(os.path.dirname(__file__), "garments/top333.png"),
143
- os.path.join(os.path.dirname(__file__), "garments/dress1.png"),
144
- os.path.join(os.path.dirname(__file__), "garments/dress2.png"),
145
- ])
146
- garment_down = gr.Image(sources='upload', type="numpy", label="lower garment")
147
- example_down = gr.Examples(inputs=garment_down,
148
- examples_per_page=5,
149
- examples=[os.path.join(os.path.dirname(__file__), "garments/bottom1.png"),
150
- os.path.join(os.path.dirname(__file__), "garments/bottom2.PNG"),
151
- os.path.join(os.path.dirname(__file__), "garments/bottom3.JPG"),
152
- os.path.join(os.path.dirname(__file__), "garments/bottom4.PNG"),
153
- os.path.join(os.path.dirname(__file__), "garments/bottom5.png"),
154
- ])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
  run_button = gr.Button(value="Run")
157
  with gr.Column():
158
  gallery = gr.Image()
159
 
160
- run_button.click(fn=get_tryon_result,
161
- inputs=[
162
- init_image,
163
- garment_top,
164
- garment_down,
165
- ],
166
- outputs=[gallery],
167
- concurrency_limit=2)
168
-
169
-
170
- # Examples
171
- gr.Markdown("## Examples")
172
- with gr.Row():
173
- reference_image1 = gr.Image(label="model", scale=1, value="examples/basemodel.png")
174
- reference_image2 = gr.Image(label="garment", scale=1, value="examples/garment1.jpg")
175
- reference_image3 = gr.Image(label="result", scale=1, value="examples/result1.png")
176
- gr.Examples(
177
- examples=[
178
- ["examples/basemodel.png", "examples/garment1.png", "examples/result1.png"],
179
- ["examples/basemodel.png", "examples/garment2.png", "examples/result2.png"],
180
- ["examples/basemodel.png", "examples/garment3.png", "examples/result3.png"],
181
- ],
182
- inputs=[reference_image1, reference_image2, reference_image3],
183
- label=None,
184
- )
 
 
 
 
 
 
 
185
 
186
  if __name__ == "__main__":
187
- ip = requests.get('http://ifconfig.me/ip', timeout=1).text.strip()
188
  print("ip address alibaba", ip)
189
  demo.queue(max_size=10)
190
  demo.launch()
191
-
 
1
+ import asyncio
2
+ import base64
3
+ import json
4
  import os
5
+ import random
6
+
7
  import cv2
8
+ import gradio as gr
9
  import numpy as np
10
+ import requests
 
11
  from PIL import Image, ImageDraw, ImageFont
 
12
 
 
 
 
13
  # from IPython import embed
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 Oroton": "models/oroton/model.png",
20
+ "AI Model Rouyan_0": "models/rouyan_new/Rouyan_0.png",
21
+ "AI Model Rouyan_1": "models/rouyan_new/Rouyan_1.png",
22
+ "AI Model Rouyan_2": "models/rouyan_new/Rouyan_2.png",
23
+ "AI Model Eva_0": "models/eva/Eva_0.png",
24
+ "AI Model Eva_1": "models/eva/Eva_1.png",
25
+ "AI Model Simon_0": "models/simon_online/Simon_0.png",
26
+ "AI Model Simon_1": "models/simon_online/Simon_1.png",
27
+ "AI Model Xuanxuan_0": "models/xiaoxuan_online/Xuanxuan_0.png",
28
+ "AI Model Xuanxuan_1": "models/xiaoxuan_online/Xuanxuan_1.png",
29
+ "AI Model Xuanxuan_2": "models/xiaoxuan_online/Xuanxuan_2.png",
30
+ "AI Model Yaqi_0": "models/yaqi/Yaqi_0.png",
31
+ "AI Model Yaqi_1": "models/yaqi/Yaqi_1.png",
32
+ "AI Model Yaqi_2": "models/yaqi/Yaqi_2.png",
33
+ "AI Model Yaqi_3": "models/yaqi/Yaqi_3.png",
34
+ "AI Model Yifeng_0": "models/yifeng_online/Yifeng_0.png",
35
+ "AI Model Yifeng_1": "models/yifeng_online/Yifeng_1.png",
36
+ "AI Model Yifeng_2": "models/yifeng_online/Yifeng_2.png",
37
+ "AI Model Yifeng_3": "models/yifeng_online/Yifeng_3.png",
38
  }
39
 
 
40
 
41
+ def add_waterprint(img):
42
  h, w, _ = img.shape
43
+ img = cv2.putText(
44
+ img,
45
+ "Powered by OutfitAnyone",
46
+ (int(0.3 * w), h - 20),
47
+ cv2.FONT_HERSHEY_PLAIN,
48
+ 2,
49
+ (128, 128, 128),
50
+ 2,
51
+ cv2.LINE_AA,
52
+ )
53
 
54
  return img
55
 
56
 
57
  def get_tryon_result(model_name, garment1, garment2, seed=1234):
 
58
  # model_name = "AI Model " + model_name.split("\\")[-1].split(".")[0] # windows
59
+ model_name = "AI Model " + model_name.split("/")[-1].split(".")[0] # linux
60
  print(model_name)
61
 
62
+ encoded_garment1 = cv2.imencode(".jpg", garment1)[1].tobytes()
63
+ encoded_garment1 = base64.b64encode(encoded_garment1).decode("utf-8")
64
 
65
  if garment2 is not None:
66
+ encoded_garment2 = cv2.imencode(".jpg", garment2)[1].tobytes()
67
+ encoded_garment2 = base64.b64encode(encoded_garment2).decode("utf-8")
68
  else:
69
+ encoded_garment2 = ""
70
 
71
+ url = os.environ["OA_IP_ADDRESS"]
72
+ headers = {"Content-Type": "application/json"}
73
  seed = random.randint(0, 1222222222)
74
  data = {
75
  "garment1": encoded_garment1,
76
  "garment2": encoded_garment2,
77
  "model_name": model_name,
78
+ "seed": seed,
79
  }
80
  response = requests.post(url, headers=headers, data=json.dumps(data))
81
  print("response code", response.status_code)
82
  if response.status_code == 200:
83
  result = response.json()
84
+ result = base64.b64decode(result["images"][0])
85
  result_np = np.frombuffer(result, np.uint8)
86
  result_img = cv2.imdecode(result_np, cv2.IMREAD_UNCHANGED)
87
  else:
88
+ print("server error!")
89
 
 
90
  final_img = add_waterprint(result_img)
91
 
92
  return final_img
93
 
94
 
95
+ with gr.Blocks(
96
+ css=".output-image, .input-image, .image-preview {height: 400px !important} "
97
+ ) as demo:
98
  # gr.Markdown("# Outfit Anyone v0.9")
99
  gr.HTML(
100
  """
 
102
  <a href="https://github.com/HumanAIGC/OutfitAnyone" style="margin-right: 20px; text-decoration: none; display: flex; align-items: center;">
103
  </a>
104
  <div>
105
+ <h1 >Oroton X AKQA</h1>
 
 
 
 
 
 
 
106
  </div>
107
  </div>
108
+ """
109
+ )
110
  with gr.Row():
111
  with gr.Column():
112
+ init_image = gr.Image(
113
+ sources="clipboard", type="filepath", label="model", value=model
114
+ )
115
+ example = gr.Examples(
116
+ inputs=init_image,
117
+ examples_per_page=4,
118
+ examples=[
119
+ os.path.join(
120
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Oroton")
121
+ )
122
+ os.path.join(
123
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Rouyan_0")
124
+ ),
125
+ os.path.join(
126
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Rouyan_2")
127
+ ),
128
+ os.path.join(
129
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Eva_0")
130
+ ),
131
+ os.path.join(
132
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Simon_1")
133
+ ),
134
+ os.path.join(
135
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Eva_1")
136
+ ),
137
+ os.path.join(
138
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Simon_0")
139
+ ),
140
+ os.path.join(
141
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Xuanxuan_0")
142
+ ),
143
+ os.path.join(
144
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Xuanxuan_2")
145
+ ),
146
+ os.path.join(
147
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Yaqi_1")
148
+ ),
149
+ os.path.join(
150
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Yifeng_0")
151
+ ),
152
+ os.path.join(
153
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Yifeng_3")
154
+ ),
155
+ os.path.join(
156
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Rouyan_1")
157
+ ),
158
+ os.path.join(
159
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Yifeng_2")
160
+ ),
161
+ os.path.join(
162
+ os.path.dirname(__file__), MODEL_MAP.get("AI Model Yaqi_0")
163
+ ),
164
+ ],
165
+ )
166
  with gr.Column():
167
  gr.HTML(
168
  """
169
  <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
170
  <div>
171
+ <h3>AKQA</h3>
 
172
  </div>
173
  </div>
174
+ """
175
+ )
176
  with gr.Row():
177
+ garment_top = gr.Image(
178
+ sources="upload", type="numpy", label="top garment"
179
+ )
180
+ example_top = gr.Examples(
181
+ inputs=garment_top,
182
+ examples_per_page=4,
183
+ examples=[
184
+ os.path.join(
185
+ os.path.dirname(__file__), "garments/oroton_dress1.JPG"
186
+ ),
187
+ os.path.join(
188
+ os.path.dirname(__file__), "garments/oroton_dress2.png"
189
+ ),
190
+ os.path.join(
191
+ os.path.dirname(__file__), "garments/oroton_dress3.png"
192
+ ),
193
+ os.path.join(
194
+ os.path.dirname(__file__), "garments/oroton_shirt1.png"
195
+ ),
196
+ ],
197
+ )
198
+ garment_down = gr.Image(
199
+ sources="upload", type="numpy", label="lower garment"
200
+ )
201
+ example_down = gr.Examples(
202
+ inputs=garment_down,
203
+ examples_per_page=5,
204
+ examples=[
205
+ os.path.join(os.path.dirname(__file__), "garments/bottom1.png"),
206
+ os.path.join(os.path.dirname(__file__), "garments/bottom2.PNG"),
207
+ os.path.join(os.path.dirname(__file__), "garments/bottom3.JPG"),
208
+ os.path.join(os.path.dirname(__file__), "garments/bottom4.PNG"),
209
+ os.path.join(os.path.dirname(__file__), "garments/bottom5.png"),
210
+ ],
211
+ )
212
 
213
  run_button = gr.Button(value="Run")
214
  with gr.Column():
215
  gallery = gr.Image()
216
 
217
+ run_button.click(
218
+ fn=get_tryon_result,
219
+ inputs=[
220
+ init_image,
221
+ garment_top,
222
+ garment_down,
223
+ ],
224
+ outputs=[gallery],
225
+ concurrency_limit=2,
226
+ )
227
+
228
+ # # Examples
229
+ # gr.Markdown("## Examples")
230
+ # with gr.Row():
231
+ # reference_image1 = gr.Image(
232
+ # label="model", scale=1, value="examples/basemodel.png"
233
+ # )
234
+ # reference_image2 = gr.Image(
235
+ # label="garment", scale=1, value="examples/garment1.jpg"
236
+ # )
237
+ # reference_image3 = gr.Image(
238
+ # label="result", scale=1, value="examples/result1.png"
239
+ # )
240
+ # gr.Examples(
241
+ # examples=[
242
+ # ["examples/basemodel.png", "examples/garment1.png", "examples/result1.png"],
243
+ # ["examples/basemodel.png", "examples/garment2.png", "examples/result2.png"],
244
+ # ["examples/basemodel.png", "examples/garment3.png", "examples/result3.png"],
245
+ # ],
246
+ # inputs=[reference_image1, reference_image2, reference_image3],
247
+ # label=None,
248
+ # )
249
 
250
  if __name__ == "__main__":
251
+ ip = requests.get("http://ifconfig.me/ip", timeout=1).text.strip()
252
  print("ip address alibaba", ip)
253
  demo.queue(max_size=10)
254
  demo.launch()
 
garments/oroton_dress1.png ADDED
garments/oroton_dress2.png ADDED
garments/oroton_dress3.png ADDED
garments/oroton_shirt1.png ADDED
models/oroton/model.png ADDED