Spaces:
Runtime error
Runtime error
Bhargavssss
commited on
Commit
•
e352db4
1
Parent(s):
915bdc3
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,12 @@
|
|
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 |
-
|
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',
|
@@ -35,62 +29,63 @@ MODEL_MAP = {
|
|
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,
|
|
|
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 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
encoded_garment2 = ''
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
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 |
-
|
84 |
|
|
|
85 |
|
86 |
|
87 |
-
with gr.Blocks(css
|
88 |
# gr.Markdown("# Outfit Anyone v0.9")
|
89 |
gr.HTML(
|
90 |
"""
|
91 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
</div>
|
95 |
</div>
|
96 |
""")
|
@@ -105,8 +100,10 @@ with gr.Blocks(css = ".output-image, .input-image, .image-preview {height: 400px
|
|
105 |
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_1')),
|
106 |
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Eva_1')),
|
107 |
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_0')),
|
108 |
-
os.path.join(os.path.dirname(__file__),
|
109 |
-
|
|
|
|
|
110 |
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yaqi_1')),
|
111 |
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_0')),
|
112 |
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_3')),
|
@@ -119,12 +116,13 @@ with gr.Blocks(css = ".output-image, .input-image, .image-preview {height: 400px
|
|
119 |
"""
|
120 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
121 |
<div>
|
122 |
-
|
|
|
123 |
</div>
|
124 |
</div>
|
125 |
""")
|
126 |
with gr.Row():
|
127 |
-
garment_top = gr.Image(sources='upload', type="
|
128 |
example_top = gr.Examples(inputs=garment_top,
|
129 |
examples_per_page=5,
|
130 |
examples=[os.path.join(os.path.dirname(__file__), "garments/top222.JPG"),
|
@@ -132,8 +130,8 @@ with gr.Blocks(css = ".output-image, .input-image, .image-preview {height: 400px
|
|
132 |
os.path.join(os.path.dirname(__file__), "garments/top333.png"),
|
133 |
os.path.join(os.path.dirname(__file__), "garments/dress1.png"),
|
134 |
os.path.join(os.path.dirname(__file__), "garments/dress2.png"),
|
135 |
-
|
136 |
-
garment_down = gr.Image(sources='upload', type="
|
137 |
example_down = gr.Examples(inputs=garment_down,
|
138 |
examples_per_page=5,
|
139 |
examples=[os.path.join(os.path.dirname(__file__), "garments/bottom1.png"),
|
@@ -141,28 +139,27 @@ with gr.Blocks(css = ".output-image, .input-image, .image-preview {height: 400px
|
|
141 |
os.path.join(os.path.dirname(__file__), "garments/bottom3.JPG"),
|
142 |
os.path.join(os.path.dirname(__file__), "garments/bottom4.PNG"),
|
143 |
os.path.join(os.path.dirname(__file__), "garments/bottom5.png"),
|
144 |
-
|
145 |
|
146 |
run_button = gr.Button(value="Run")
|
147 |
with gr.Column():
|
148 |
gallery = gr.Image()
|
149 |
|
150 |
-
run_button.click(fn=get_tryon_result,
|
151 |
inputs=[
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
outputs=[gallery],
|
157 |
concurrency_limit=2)
|
158 |
-
|
159 |
|
160 |
# Examples
|
161 |
gr.Markdown("## Examples")
|
162 |
with gr.Row():
|
163 |
-
reference_image1
|
164 |
-
reference_image2
|
165 |
-
reference_image3
|
166 |
gr.Examples(
|
167 |
examples=[
|
168 |
["examples/basemodel.png", "examples/garment1.png", "examples/result1.png"],
|
@@ -174,8 +171,5 @@ with gr.Blocks(css = ".output-image, .input-image, .image-preview {height: 400px
|
|
174 |
)
|
175 |
|
176 |
if __name__ == "__main__":
|
177 |
-
ip = requests.get('http://ifconfig.me/ip', timeout=1).text.strip()
|
178 |
-
print("ip address alibaba", ip)
|
179 |
demo.queue(max_size=10)
|
180 |
-
demo.launch(share=
|
181 |
-
|
|
|
1 |
import os
|
2 |
import cv2
|
|
|
|
|
3 |
import random
|
|
|
|
|
|
|
|
|
|
|
4 |
import gradio as gr
|
5 |
+
from gradio_client import Client, handle_file
|
6 |
|
7 |
machine_number = 0
|
8 |
model = os.path.join(os.path.dirname(__file__), "models/eva/Eva_0.png")
|
9 |
+
client = Client("HumanAIGC/OutfitAnyone")
|
10 |
|
11 |
MODEL_MAP = {
|
12 |
"AI Model Rouyan_0": 'models/rouyan_new/Rouyan_0.png',
|
|
|
29 |
"AI Model Yifeng_3": 'models/yifeng_online/Yifeng_3.png',
|
30 |
}
|
31 |
|
|
|
32 |
|
33 |
+
def add_waterprint(img):
|
34 |
h, w, _ = img.shape
|
35 |
+
img = cv2.putText(img, 'Powered by OutfitAnyone', (int(0.3 * w), h - 20), cv2.FONT_HERSHEY_PLAIN, 2,
|
36 |
+
(128, 128, 128), 2, cv2.LINE_AA)
|
37 |
|
38 |
return img
|
39 |
|
40 |
|
41 |
def get_tryon_result(model_name, garment1, garment2, seed=1234):
|
42 |
+
# _model = "AI Model " + model_name.split("\\")[-1].split(".")[0] # windows
|
43 |
+
_model = "AI Model " + model_name.split("/")[-1].split(".")[0] # linux
|
44 |
+
print("Use Model:", _model)
|
45 |
+
seed = random.randint(0, 1222222222)
|
46 |
+
garment1 = handle_file(garment1) if garment1 else None
|
47 |
+
garment2 = handle_file(garment2) if garment2 else None
|
48 |
+
result = client.predict(
|
49 |
+
handle_file(model_name),
|
50 |
+
garment1,
|
51 |
+
garment2,
|
52 |
+
api_name="/get_tryon_result",
|
53 |
+
fn_index=seed
|
54 |
+
)
|
55 |
+
final_img = remove_watermark2(result)
|
56 |
+
return final_img
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
def remove_watermark2(path):
|
60 |
+
img = cv2.imread(path)
|
61 |
+
img_ = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
62 |
+
h, w, _ = img.shape
|
|
|
63 |
|
64 |
+
y_start = max(h - 45, 0)
|
65 |
+
y_end = h
|
66 |
+
x_start = max(int(0.3 * w), 0)
|
67 |
+
x_end = w
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
+
img_[y_start:y_end, x_start:x_end, :] = [255, 255, 255]
|
70 |
|
71 |
+
return img_
|
72 |
|
73 |
|
74 |
+
with gr.Blocks(css=".output-image, .input-image, .image-preview {height: 400px !important} ") as demo:
|
75 |
# gr.Markdown("# Outfit Anyone v0.9")
|
76 |
gr.HTML(
|
77 |
"""
|
78 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
79 |
+
<a href="https://github.com/HumanAIGC/OutfitAnyone" style="margin-right: 20px; text-decoration: none; display: flex; align-items: center;">
|
80 |
+
</a>
|
81 |
+
<div>
|
82 |
+
<h1 >Outfit Anyone: Ultra-high quality virtual try-on for Any Clothing and Any Person</h1>
|
83 |
+
<h4 >v0.9</h4>
|
84 |
+
<h5 style="margin: 0;">If you like our project, please give us a star on Github to stay updated with the latest developments.</h5>
|
85 |
+
<div style="display: flex; justify-content: center; align-items: center; text-align: center;>
|
86 |
+
<a href="https://github.com/HumanAIGC/OutfitAnyone"><img src="https://img.shields.io/badge/Arxiv-0000.00000-red"></a>
|
87 |
+
<a href='https://humanaigc.github.io/outfit-anyone/'><img src='https://img.shields.io/badge/Project_Page-OutfitAnyone-green' alt='Project Page'></a>
|
88 |
+
</div>
|
89 |
</div>
|
90 |
</div>
|
91 |
""")
|
|
|
100 |
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_1')),
|
101 |
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Eva_1')),
|
102 |
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_0')),
|
103 |
+
os.path.join(os.path.dirname(__file__),
|
104 |
+
MODEL_MAP.get('AI Model Xuanxuan_0')),
|
105 |
+
os.path.join(os.path.dirname(__file__),
|
106 |
+
MODEL_MAP.get('AI Model Xuanxuan_2')),
|
107 |
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yaqi_1')),
|
108 |
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_0')),
|
109 |
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_3')),
|
|
|
116 |
"""
|
117 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
118 |
<div>
|
119 |
+
<h3>Models are fixed and cannot be uploaded or modified; we only support users uploading their own garments.</h3>
|
120 |
+
<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>
|
121 |
</div>
|
122 |
</div>
|
123 |
""")
|
124 |
with gr.Row():
|
125 |
+
garment_top = gr.Image(sources='upload', type="filepath", label="top garment")
|
126 |
example_top = gr.Examples(inputs=garment_top,
|
127 |
examples_per_page=5,
|
128 |
examples=[os.path.join(os.path.dirname(__file__), "garments/top222.JPG"),
|
|
|
130 |
os.path.join(os.path.dirname(__file__), "garments/top333.png"),
|
131 |
os.path.join(os.path.dirname(__file__), "garments/dress1.png"),
|
132 |
os.path.join(os.path.dirname(__file__), "garments/dress2.png"),
|
133 |
+
])
|
134 |
+
garment_down = gr.Image(sources='upload', type="filepath", label="lower garment")
|
135 |
example_down = gr.Examples(inputs=garment_down,
|
136 |
examples_per_page=5,
|
137 |
examples=[os.path.join(os.path.dirname(__file__), "garments/bottom1.png"),
|
|
|
139 |
os.path.join(os.path.dirname(__file__), "garments/bottom3.JPG"),
|
140 |
os.path.join(os.path.dirname(__file__), "garments/bottom4.PNG"),
|
141 |
os.path.join(os.path.dirname(__file__), "garments/bottom5.png"),
|
142 |
+
])
|
143 |
|
144 |
run_button = gr.Button(value="Run")
|
145 |
with gr.Column():
|
146 |
gallery = gr.Image()
|
147 |
|
148 |
+
run_button.click(fn=get_tryon_result,
|
149 |
inputs=[
|
150 |
+
init_image,
|
151 |
+
garment_top,
|
152 |
+
garment_down,
|
153 |
+
],
|
154 |
outputs=[gallery],
|
155 |
concurrency_limit=2)
|
|
|
156 |
|
157 |
# Examples
|
158 |
gr.Markdown("## Examples")
|
159 |
with gr.Row():
|
160 |
+
reference_image1 = gr.Image(label="model", scale=1, value="examples/basemodel.png")
|
161 |
+
reference_image2 = gr.Image(label="garment", scale=1, value="examples/garment1.jpg")
|
162 |
+
reference_image3 = gr.Image(label="result", scale=1, value="examples/result1.png")
|
163 |
gr.Examples(
|
164 |
examples=[
|
165 |
["examples/basemodel.png", "examples/garment1.png", "examples/result1.png"],
|
|
|
171 |
)
|
172 |
|
173 |
if __name__ == "__main__":
|
|
|
|
|
174 |
demo.queue(max_size=10)
|
175 |
+
demo.launch(share=False, server_name='127.0.0.1', server_port=6006)
|
|