Spaces:
Runtime error
Runtime error
Bhargavssss
commited on
Commit
•
253f337
1
Parent(s):
fc5528c
Update app.py
Browse files
app.py
CHANGED
@@ -1,160 +1,160 @@
|
|
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',
|
13 |
-
"AI Model Rouyan_1": 'models/rouyan_new/Rouyan_1.png',
|
14 |
-
"AI Model Rouyan_2": 'models/rouyan_new/Rouyan_2.png',
|
15 |
-
"AI Model Eva_0": 'models/eva/Eva_0.png',
|
16 |
-
"AI Model Eva_1": 'models/eva/Eva_1.png',
|
17 |
-
"AI Model Simon_0": 'models/simon_online/Simon_0.png',
|
18 |
-
"AI Model Simon_1": 'models/simon_online/Simon_1.png',
|
19 |
-
"AI Model Xuanxuan_0": 'models/xiaoxuan_online/Xuanxuan_0.png',
|
20 |
-
"AI Model Xuanxuan_1": 'models/xiaoxuan_online/Xuanxuan_1.png',
|
21 |
-
"AI Model Xuanxuan_2": 'models/xiaoxuan_online/Xuanxuan_2.png',
|
22 |
-
"AI Model Yaqi_0": 'models/yaqi/Yaqi_0.png',
|
23 |
-
"AI Model Yaqi_1": 'models/yaqi/Yaqi_1.png',
|
24 |
-
"AI Model Yaqi_2": 'models/yaqi/Yaqi_2.png',
|
25 |
-
"AI Model Yaqi_3": 'models/yaqi/Yaqi_3.png',
|
26 |
-
"AI Model Yifeng_0": 'models/yifeng_online/Yifeng_0.png',
|
27 |
-
"AI Model Yifeng_1": 'models/yifeng_online/Yifeng_1.png',
|
28 |
-
"AI Model Yifeng_2": 'models/yifeng_online/Yifeng_2.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 Infomerica', (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 |
-
|
79 |
-
</div>
|
80 |
-
</div>
|
81 |
-
""")
|
82 |
-
with gr.Row():
|
83 |
-
with gr.Column():
|
84 |
-
init_image = gr.Image(sources='clipboard', type="filepath", label="model", value=model)
|
85 |
-
example = gr.Examples(inputs=init_image,
|
86 |
-
examples_per_page=4,
|
87 |
-
examples=[os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_0')),
|
88 |
-
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_2')),
|
89 |
-
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Eva_0')),
|
90 |
-
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_1')),
|
91 |
-
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Eva_1')),
|
92 |
-
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_0')),
|
93 |
-
os.path.join(os.path.dirname(__file__),
|
94 |
-
MODEL_MAP.get('AI Model Xuanxuan_0')),
|
95 |
-
os.path.join(os.path.dirname(__file__),
|
96 |
-
MODEL_MAP.get('AI Model Xuanxuan_2')),
|
97 |
-
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yaqi_1')),
|
98 |
-
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_0')),
|
99 |
-
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_3')),
|
100 |
-
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_1')),
|
101 |
-
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_2')),
|
102 |
-
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yaqi_0')),
|
103 |
-
])
|
104 |
-
with gr.Column():
|
105 |
-
gr.HTML(
|
106 |
-
"""
|
107 |
-
|
108 |
-
""")
|
109 |
-
with gr.Row():
|
110 |
-
garment_top = gr.Image(sources='upload', type="filepath", label="top garment")
|
111 |
-
example_top = gr.Examples(inputs=garment_top,
|
112 |
-
examples_per_page=5,
|
113 |
-
examples=[os.path.join(os.path.dirname(__file__), "garments/top222.JPG"),
|
114 |
-
os.path.join(os.path.dirname(__file__), "garments/top5.png"),
|
115 |
-
os.path.join(os.path.dirname(__file__), "garments/top333.png"),
|
116 |
-
os.path.join(os.path.dirname(__file__), "garments/dress1.png"),
|
117 |
-
os.path.join(os.path.dirname(__file__), "garments/dress2.png"),
|
118 |
-
])
|
119 |
-
garment_down = gr.Image(sources='upload', type="filepath", label="lower garment")
|
120 |
-
example_down = gr.Examples(inputs=garment_down,
|
121 |
-
examples_per_page=5,
|
122 |
-
examples=[os.path.join(os.path.dirname(__file__), "garments/bottom1.png"),
|
123 |
-
os.path.join(os.path.dirname(__file__), "garments/bottom2.PNG"),
|
124 |
-
os.path.join(os.path.dirname(__file__), "garments/bottom3.JPG"),
|
125 |
-
os.path.join(os.path.dirname(__file__), "garments/bottom4.PNG"),
|
126 |
-
os.path.join(os.path.dirname(__file__), "garments/bottom5.png"),
|
127 |
-
])
|
128 |
-
|
129 |
-
run_button = gr.Button(value="Run")
|
130 |
-
with gr.Column():
|
131 |
-
gallery = gr.Image()
|
132 |
-
|
133 |
-
run_button.click(fn=get_tryon_result,
|
134 |
-
inputs=[
|
135 |
-
init_image,
|
136 |
-
garment_top,
|
137 |
-
garment_down,
|
138 |
-
],
|
139 |
-
outputs=[gallery],
|
140 |
-
concurrency_limit=2)
|
141 |
-
|
142 |
-
# Examples
|
143 |
-
gr.Markdown("## Examples")
|
144 |
-
with gr.Row():
|
145 |
-
reference_image1 = gr.Image(label="model", scale=1, value="examples/basemodel.png")
|
146 |
-
reference_image2 = gr.Image(label="garment", scale=1, value="examples/garment1.jpg")
|
147 |
-
reference_image3 = gr.Image(label="result", scale=1, value="examples/result1.png")
|
148 |
-
gr.Examples(
|
149 |
-
examples=[
|
150 |
-
["examples/basemodel.png", "examples/garment1.png", "examples/result1.png"],
|
151 |
-
["examples/basemodel.png", "examples/garment2.png", "examples/result2.png"],
|
152 |
-
["examples/basemodel.png", "examples/garment3.png", "examples/result3.png"],
|
153 |
-
],
|
154 |
-
inputs=[reference_image1, reference_image2, reference_image3],
|
155 |
-
label=None,
|
156 |
-
)
|
157 |
-
|
158 |
-
if __name__ == "__main__":
|
159 |
-
demo.queue(max_size=10)
|
160 |
-
demo.launch(
|
|
|
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',
|
13 |
+
"AI Model Rouyan_1": 'models/rouyan_new/Rouyan_1.png',
|
14 |
+
"AI Model Rouyan_2": 'models/rouyan_new/Rouyan_2.png',
|
15 |
+
"AI Model Eva_0": 'models/eva/Eva_0.png',
|
16 |
+
"AI Model Eva_1": 'models/eva/Eva_1.png',
|
17 |
+
"AI Model Simon_0": 'models/simon_online/Simon_0.png',
|
18 |
+
"AI Model Simon_1": 'models/simon_online/Simon_1.png',
|
19 |
+
"AI Model Xuanxuan_0": 'models/xiaoxuan_online/Xuanxuan_0.png',
|
20 |
+
"AI Model Xuanxuan_1": 'models/xiaoxuan_online/Xuanxuan_1.png',
|
21 |
+
"AI Model Xuanxuan_2": 'models/xiaoxuan_online/Xuanxuan_2.png',
|
22 |
+
"AI Model Yaqi_0": 'models/yaqi/Yaqi_0.png',
|
23 |
+
"AI Model Yaqi_1": 'models/yaqi/Yaqi_1.png',
|
24 |
+
"AI Model Yaqi_2": 'models/yaqi/Yaqi_2.png',
|
25 |
+
"AI Model Yaqi_3": 'models/yaqi/Yaqi_3.png',
|
26 |
+
"AI Model Yifeng_0": 'models/yifeng_online/Yifeng_0.png',
|
27 |
+
"AI Model Yifeng_1": 'models/yifeng_online/Yifeng_1.png',
|
28 |
+
"AI Model Yifeng_2": 'models/yifeng_online/Yifeng_2.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 Infomerica', (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 |
+
|
79 |
+
</div>
|
80 |
+
</div>
|
81 |
+
""")
|
82 |
+
with gr.Row():
|
83 |
+
with gr.Column():
|
84 |
+
init_image = gr.Image(sources='clipboard', type="filepath", label="model", value=model)
|
85 |
+
example = gr.Examples(inputs=init_image,
|
86 |
+
examples_per_page=4,
|
87 |
+
examples=[os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_0')),
|
88 |
+
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_2')),
|
89 |
+
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Eva_0')),
|
90 |
+
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_1')),
|
91 |
+
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Eva_1')),
|
92 |
+
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_0')),
|
93 |
+
os.path.join(os.path.dirname(__file__),
|
94 |
+
MODEL_MAP.get('AI Model Xuanxuan_0')),
|
95 |
+
os.path.join(os.path.dirname(__file__),
|
96 |
+
MODEL_MAP.get('AI Model Xuanxuan_2')),
|
97 |
+
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yaqi_1')),
|
98 |
+
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_0')),
|
99 |
+
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_3')),
|
100 |
+
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_1')),
|
101 |
+
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_2')),
|
102 |
+
os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yaqi_0')),
|
103 |
+
])
|
104 |
+
with gr.Column():
|
105 |
+
gr.HTML(
|
106 |
+
"""
|
107 |
+
|
108 |
+
""")
|
109 |
+
with gr.Row():
|
110 |
+
garment_top = gr.Image(sources='upload', type="filepath", label="top garment")
|
111 |
+
example_top = gr.Examples(inputs=garment_top,
|
112 |
+
examples_per_page=5,
|
113 |
+
examples=[os.path.join(os.path.dirname(__file__), "garments/top222.JPG"),
|
114 |
+
os.path.join(os.path.dirname(__file__), "garments/top5.png"),
|
115 |
+
os.path.join(os.path.dirname(__file__), "garments/top333.png"),
|
116 |
+
os.path.join(os.path.dirname(__file__), "garments/dress1.png"),
|
117 |
+
os.path.join(os.path.dirname(__file__), "garments/dress2.png"),
|
118 |
+
])
|
119 |
+
garment_down = gr.Image(sources='upload', type="filepath", label="lower garment")
|
120 |
+
example_down = gr.Examples(inputs=garment_down,
|
121 |
+
examples_per_page=5,
|
122 |
+
examples=[os.path.join(os.path.dirname(__file__), "garments/bottom1.png"),
|
123 |
+
os.path.join(os.path.dirname(__file__), "garments/bottom2.PNG"),
|
124 |
+
os.path.join(os.path.dirname(__file__), "garments/bottom3.JPG"),
|
125 |
+
os.path.join(os.path.dirname(__file__), "garments/bottom4.PNG"),
|
126 |
+
os.path.join(os.path.dirname(__file__), "garments/bottom5.png"),
|
127 |
+
])
|
128 |
+
|
129 |
+
run_button = gr.Button(value="Run")
|
130 |
+
with gr.Column():
|
131 |
+
gallery = gr.Image()
|
132 |
+
|
133 |
+
run_button.click(fn=get_tryon_result,
|
134 |
+
inputs=[
|
135 |
+
init_image,
|
136 |
+
garment_top,
|
137 |
+
garment_down,
|
138 |
+
],
|
139 |
+
outputs=[gallery],
|
140 |
+
concurrency_limit=2)
|
141 |
+
|
142 |
+
# Examples
|
143 |
+
gr.Markdown("## Examples")
|
144 |
+
with gr.Row():
|
145 |
+
reference_image1 = gr.Image(label="model", scale=1, value="examples/basemodel.png")
|
146 |
+
reference_image2 = gr.Image(label="garment", scale=1, value="examples/garment1.jpg")
|
147 |
+
reference_image3 = gr.Image(label="result", scale=1, value="examples/result1.png")
|
148 |
+
gr.Examples(
|
149 |
+
examples=[
|
150 |
+
["examples/basemodel.png", "examples/garment1.png", "examples/result1.png"],
|
151 |
+
["examples/basemodel.png", "examples/garment2.png", "examples/result2.png"],
|
152 |
+
["examples/basemodel.png", "examples/garment3.png", "examples/result3.png"],
|
153 |
+
],
|
154 |
+
inputs=[reference_image1, reference_image2, reference_image3],
|
155 |
+
label=None,
|
156 |
+
)
|
157 |
+
|
158 |
+
if __name__ == "__main__":
|
159 |
+
demo.queue(max_size=10)
|
160 |
+
demo.launch()
|