selfitcamera
commited on
Commit
•
3dd3b51
1
Parent(s):
f7f38e1
setup
Browse files
app2.py
DELETED
@@ -1,174 +0,0 @@
|
|
1 |
-
|
2 |
-
from utils import *
|
3 |
-
|
4 |
-
|
5 |
-
def onUpload():
|
6 |
-
return ""
|
7 |
-
|
8 |
-
|
9 |
-
def onClick(cloth_id, pose_image, pose_id, size, request: gr.Request):
|
10 |
-
if pose_image is None:
|
11 |
-
return None, "no pose image found !"
|
12 |
-
# pose_id, cloth_id = pose_id['label'], cloth_id['label']
|
13 |
-
# print(pose_id, cloth_id, size, (pose_image is None), len(pose_id)>0)
|
14 |
-
if len(pose_id)>0:
|
15 |
-
res = get_result_example(cloth_id, pose_id)
|
16 |
-
print(res)
|
17 |
-
assert os.path.exists(res), res
|
18 |
-
return res, "Done! Use the pre-run results directly, the cloth size does not take effect "
|
19 |
-
else:
|
20 |
-
try:
|
21 |
-
client_ip = request.client.host
|
22 |
-
x_forwarded_for = dict(request.headers).get('x-forwarded-for')
|
23 |
-
if x_forwarded_for:
|
24 |
-
client_ip = x_forwarded_for
|
25 |
-
timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
|
26 |
-
isUpload = upload_pose_img(ApiUrl, OpenId, ApiKey, client_ip, timeId, pose_image)
|
27 |
-
if isUpload==0:
|
28 |
-
return None, "fail to upload"
|
29 |
-
elif isUpload==-1:
|
30 |
-
return None, "There is a running task already, please wait and check the history tab"
|
31 |
-
elif isUpload==-2:
|
32 |
-
return None, "can not creat task, you have exhausted free trial quota"
|
33 |
-
|
34 |
-
taskId = publicClothSwap(ApiUrl, OpenId, ApiKey, client_ip, cloth_id, timeId, size)
|
35 |
-
if taskId==0:
|
36 |
-
return None, "fail to public you task"
|
37 |
-
|
38 |
-
max_try = 1
|
39 |
-
wait_s = 30
|
40 |
-
for i in range(max_try):
|
41 |
-
time.sleep(wait_s)
|
42 |
-
state = getInfRes(ApiUrl, OpenId, ApiKey, client_ip, timeId)
|
43 |
-
if state=='stateIs-1':
|
44 |
-
return None, "task failed, it may be that no human was detected, or there may be illegal content, etc. "
|
45 |
-
elif state=='stateIs0':
|
46 |
-
return None, "task not public success"
|
47 |
-
elif len(state)>20:
|
48 |
-
return state, "task finished"
|
49 |
-
elif (not state.startswith('stateIs')):
|
50 |
-
# return None, 'task is in queue, position is '+str(state)
|
51 |
-
pass
|
52 |
-
else:
|
53 |
-
return None, state
|
54 |
-
return None, "task has been created successfully, you can refresh the page 5~15 mins latter, and check the following history tab"
|
55 |
-
except Exception as e:
|
56 |
-
print(e)
|
57 |
-
return None, "fail to create task"
|
58 |
-
|
59 |
-
|
60 |
-
def onLoad(request: gr.Request):
|
61 |
-
client_ip = request.client.host
|
62 |
-
x_forwarded_for = dict(request.headers).get('x-forwarded-for')
|
63 |
-
if x_forwarded_for:
|
64 |
-
client_ip = x_forwarded_for
|
65 |
-
his_datas = [None for _ in range(10)]
|
66 |
-
try:
|
67 |
-
infs = getAllInfs(ApiUrl, OpenId, ApiKey, client_ip)
|
68 |
-
print(client_ip, 'history infs: ', len(infs))
|
69 |
-
for i, inf in enumerate(infs):
|
70 |
-
if i>4: continue
|
71 |
-
his_datas[i*2] = inf['pose']
|
72 |
-
his_datas[i*2+1] = inf['res']
|
73 |
-
time.sleep(3)
|
74 |
-
except Exception as e:
|
75 |
-
print(e)
|
76 |
-
return his_datas
|
77 |
-
|
78 |
-
|
79 |
-
cloth_examples = get_cloth_examples()
|
80 |
-
pose_examples = get_pose_examples()
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
# Description
|
85 |
-
title = r"""
|
86 |
-
<h1 align="center">Outfit Anyone in the Wild: Get rid of Annoying Restrictions for Virtual Try-on Task</h1>
|
87 |
-
"""
|
88 |
-
|
89 |
-
description = r"""
|
90 |
-
<b>Official 🤗 Gradio demo</b> for <a href='https://github.com/selfitcamera/Outfit-Anyone-in-the-Wild' target='_blank'><b>Outfit Anyone in the Wild: Get rid of Annoying Restrictions for Virtual Try-on Task</b></a>.<br>
|
91 |
-
1. Clothing models are fixed in this demo, but you can create your own in SelfitCamera WeChat applet (for Chainese users).
|
92 |
-
2. You can upload your own pose photo, then click the run button and wait for 3~5 minutes to see the results.
|
93 |
-
3. After submitting the task, feel free to leave this page. Everytime you refresh this page, completed tasks will be displayed on the history tab (bind with your ip address).
|
94 |
-
4. Share your try-on photo with your friends and enjoy! 😊"""
|
95 |
-
|
96 |
-
|
97 |
-
css = """
|
98 |
-
.gradio-container {width: 85% !important}
|
99 |
-
"""
|
100 |
-
with gr.Blocks(css=css) as demo:
|
101 |
-
# description
|
102 |
-
gr.Markdown(title)
|
103 |
-
gr.Markdown(description)
|
104 |
-
|
105 |
-
with gr.Row():
|
106 |
-
with gr.Column():
|
107 |
-
with gr.Column():
|
108 |
-
# cloth_image = gr.Image(type="numpy", value=cloth_examples[0][1], label="")
|
109 |
-
cloth_image = gr.Image(sources='clipboard', type="filepath", label="",
|
110 |
-
value=cloth_examples[0][1])
|
111 |
-
cloth_id = gr.Label(value=cloth_examples[0][0], label="Clothing 3D Model", visible=False)
|
112 |
-
example = gr.Examples(inputs=[cloth_id, cloth_image],
|
113 |
-
examples_per_page=3,
|
114 |
-
examples = cloth_examples)
|
115 |
-
with gr.Column():
|
116 |
-
with gr.Column():
|
117 |
-
# pose_image = gr.Image(source='upload', value=pose_examples[0][1],
|
118 |
-
# type="numpy", label="")
|
119 |
-
pose_image = gr.Image(value=pose_examples[0][1],
|
120 |
-
type="numpy", label="")
|
121 |
-
pose_id = gr.Label(value=pose_examples[0][0], label="Pose Image", visible=False)
|
122 |
-
example_pose = gr.Examples(inputs=[pose_id, pose_image],
|
123 |
-
examples_per_page=3,
|
124 |
-
examples=pose_examples)
|
125 |
-
size_slider = gr.Slider(-2.5, 2.5, value=1, interactive=True, label="clothes size")
|
126 |
-
|
127 |
-
with gr.Column():
|
128 |
-
with gr.Column():
|
129 |
-
run_button = gr.Button(value="Run")
|
130 |
-
init_res = get_result_example(cloth_examples[0][0], pose_examples[0][0])
|
131 |
-
# res_image = gr.Image(label="result image", value=init_res, type="filepath")
|
132 |
-
res_image = gr.Image(label="result image", value=cv2.imread(init_res),
|
133 |
-
type="numpy")
|
134 |
-
info_text = gr.Textbox(value="", interactive=False,
|
135 |
-
label='runtime information')
|
136 |
-
|
137 |
-
with gr.Tab('history'):
|
138 |
-
with gr.Row():
|
139 |
-
his_pose_image1 = gr.Image(label="pose image1", interactive=False)
|
140 |
-
his_res_image1 = gr.Image(label="result image1", interactive=False)
|
141 |
-
|
142 |
-
with gr.Row():
|
143 |
-
his_pose_image2 = gr.Image(label="pose image2", interactive=False)
|
144 |
-
his_res_image2 = gr.Image(label="result image2", interactive=False)
|
145 |
-
|
146 |
-
with gr.Row():
|
147 |
-
his_pose_image3 = gr.Image(label="pose image3", interactive=False)
|
148 |
-
his_res_image3 = gr.Image(label="result image3", interactive=False)
|
149 |
-
|
150 |
-
with gr.Row():
|
151 |
-
his_pose_image4 = gr.Image(label="pose image4", interactive=False)
|
152 |
-
his_res_image4 = gr.Image(label="result image4", interactive=False)
|
153 |
-
|
154 |
-
with gr.Row():
|
155 |
-
his_pose_image5 = gr.Image(label="pose image5", interactive=False)
|
156 |
-
his_res_image5 = gr.Image(label="result image5", interactive=False)
|
157 |
-
|
158 |
-
|
159 |
-
run_button.click(fn=onClick, inputs=[cloth_id, pose_image, pose_id, size_slider],
|
160 |
-
outputs=[res_image, info_text], concurrency_limit=50)
|
161 |
-
|
162 |
-
pose_image.upload(fn=onUpload, inputs=[], outputs=[pose_id],)
|
163 |
-
demo.load(onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1,
|
164 |
-
his_pose_image2, his_res_image2, his_pose_image3, his_res_image3,
|
165 |
-
his_pose_image4, his_res_image4, his_pose_image5, his_res_image5,
|
166 |
-
])
|
167 |
-
|
168 |
-
if __name__ == "__main__":
|
169 |
-
|
170 |
-
demo.queue(max_size=50)
|
171 |
-
# demo.queue(concurrency_count=60)
|
172 |
-
# demo.launch(server_name='0.0.0.0', server_port=225)
|
173 |
-
demo.launch(server_name='0.0.0.0')
|
174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app3.py
DELETED
@@ -1,185 +0,0 @@
|
|
1 |
-
|
2 |
-
from utils import *
|
3 |
-
|
4 |
-
|
5 |
-
def onUpload():
|
6 |
-
return ""
|
7 |
-
|
8 |
-
|
9 |
-
def onClick(cloth_id, pose_image, pose_id, size, request: gr.Request):
|
10 |
-
if pose_image is None:
|
11 |
-
return None, "no pose image found !"
|
12 |
-
# pose_id, cloth_id = pose_id['label'], cloth_id['label']
|
13 |
-
# print(pose_id, cloth_id, size, (pose_image is None), len(pose_id)>0)
|
14 |
-
if len(pose_id)>0:
|
15 |
-
res = get_result_example(cloth_id, pose_id)
|
16 |
-
print(res)
|
17 |
-
assert os.path.exists(res), res
|
18 |
-
return res, "Done! Use the pre-run results directly, the cloth size does not take effect "
|
19 |
-
else:
|
20 |
-
try:
|
21 |
-
client_ip = request.client.host
|
22 |
-
x_forwarded_for = dict(request.headers).get('x-forwarded-for')
|
23 |
-
if x_forwarded_for:
|
24 |
-
client_ip = x_forwarded_for
|
25 |
-
timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
|
26 |
-
isUpload = upload_pose_img(ApiUrl, OpenId, ApiKey, client_ip, timeId, pose_image)
|
27 |
-
if isUpload==0:
|
28 |
-
return None, "fail to upload"
|
29 |
-
elif isUpload==-1:
|
30 |
-
return None, "There is a running task already, please wait and check the history tab"
|
31 |
-
elif isUpload==-2:
|
32 |
-
return None, "can not creat task, you have exhausted free trial quota"
|
33 |
-
|
34 |
-
taskId = publicClothSwap(ApiUrl, OpenId, ApiKey, client_ip, cloth_id, timeId, size)
|
35 |
-
if taskId==0:
|
36 |
-
return None, "fail to public you task"
|
37 |
-
|
38 |
-
max_try = 1
|
39 |
-
wait_s = 30
|
40 |
-
for i in range(max_try):
|
41 |
-
time.sleep(wait_s)
|
42 |
-
state = getInfRes(ApiUrl, OpenId, ApiKey, client_ip, timeId)
|
43 |
-
if state=='stateIs-1':
|
44 |
-
return None, "task failed, it may be that no human was detected, or there may be illegal content, etc. "
|
45 |
-
elif state=='stateIs0':
|
46 |
-
return None, "task not public success"
|
47 |
-
elif len(state)>20:
|
48 |
-
return state, "task finished"
|
49 |
-
elif (not state.startswith('stateIs')):
|
50 |
-
# return None, 'task is in queue, position is '+str(state)
|
51 |
-
pass
|
52 |
-
else:
|
53 |
-
return None, state
|
54 |
-
return None, "task has been created successfully, you can refresh the page 5~15 mins latter, and check the following history tab"
|
55 |
-
except Exception as e:
|
56 |
-
print(e)
|
57 |
-
return None, "fail to create task"
|
58 |
-
|
59 |
-
def onLoad(request: gr.Request):
|
60 |
-
client_ip = request.client.host
|
61 |
-
x_forwarded_for = dict(request.headers).get('x-forwarded-for')
|
62 |
-
if x_forwarded_for:
|
63 |
-
client_ip = x_forwarded_for
|
64 |
-
his_datas = [None for _ in range(10)]
|
65 |
-
try:
|
66 |
-
infs = getAllInfs(ApiUrl, OpenId, ApiKey, client_ip)
|
67 |
-
print(client_ip, 'history infs: ', len(infs))
|
68 |
-
print(infs)
|
69 |
-
for i, inf in enumerate(infs):
|
70 |
-
if i>4: continue
|
71 |
-
pose = inf['pose']
|
72 |
-
res = inf['res']
|
73 |
-
his_datas[i*2] = f"<img src=\"{pose}\" >"
|
74 |
-
his_datas[i*2+1] = f"<img src=\"{res}\" >"
|
75 |
-
time.sleep(3)
|
76 |
-
except Exception as e:
|
77 |
-
print(e)
|
78 |
-
return his_datas
|
79 |
-
|
80 |
-
|
81 |
-
cloth_examples = get_cloth_examples()
|
82 |
-
pose_examples = get_pose_examples()
|
83 |
-
|
84 |
-
|
85 |
-
# Description
|
86 |
-
title = r"""
|
87 |
-
<h1 align="center">Outfit Anyone in the Wild: Get rid of Annoying Restrictions for Virtual Try-on Task</h1>
|
88 |
-
"""
|
89 |
-
|
90 |
-
description = r"""
|
91 |
-
<b>Official 🤗 Gradio demo</b> for <a href='https://github.com/selfitcamera/Outfit-Anyone-in-the-Wild' target='_blank'><b>Outfit Anyone in the Wild: Get rid of Annoying Restrictions for Virtual Try-on Task</b></a>.<br>
|
92 |
-
1. Clothing models are fixed in this demo, but you can create your own in SelfitCamera WeChat applet (for Chainese users).
|
93 |
-
2. You can upload your own pose photo, then click the run button and wait for 3~5 minutes to see the results.
|
94 |
-
3. After submitting the task, feel free to leave this page. Everytime you refresh this page, completed tasks will be displayed on the history tab (bind with your ip address).
|
95 |
-
4. Share your try-on photo with your friends and enjoy! 😊"""
|
96 |
-
|
97 |
-
|
98 |
-
css = """
|
99 |
-
.gradio-container {width: 85% !important}
|
100 |
-
"""
|
101 |
-
with gr.Blocks(css=css) as demo:
|
102 |
-
# description
|
103 |
-
gr.Markdown(title)
|
104 |
-
gr.Markdown(description)
|
105 |
-
|
106 |
-
with gr.Row():
|
107 |
-
with gr.Column():
|
108 |
-
with gr.Column():
|
109 |
-
# cloth_image = gr.Image(type="numpy", value=cloth_examples[0][1], label="")
|
110 |
-
cloth_image = gr.Image(sources='clipboard', type="filepath", label="",
|
111 |
-
value=cloth_examples[0][1])
|
112 |
-
cloth_id = gr.Label(value=cloth_examples[0][0], label="Clothing 3D Model", visible=False)
|
113 |
-
example = gr.Examples(inputs=[cloth_id, cloth_image],
|
114 |
-
examples_per_page=3,
|
115 |
-
examples = cloth_examples)
|
116 |
-
with gr.Column():
|
117 |
-
with gr.Column():
|
118 |
-
# pose_image = gr.Image(source='upload', value=pose_examples[0][1],
|
119 |
-
# type="numpy", label="")
|
120 |
-
pose_image = gr.Image(value=pose_examples[0][1],
|
121 |
-
type="numpy", label="")
|
122 |
-
pose_id = gr.Label(value=pose_examples[0][0], label="Pose Image", visible=False)
|
123 |
-
example_pose = gr.Examples(inputs=[pose_id, pose_image],
|
124 |
-
examples_per_page=3,
|
125 |
-
examples=pose_examples)
|
126 |
-
size_slider = gr.Slider(-2.5, 2.5, value=1, interactive=True, label="clothes size")
|
127 |
-
|
128 |
-
with gr.Column():
|
129 |
-
with gr.Column():
|
130 |
-
run_button = gr.Button(value="Run")
|
131 |
-
init_res = get_result_example(cloth_examples[0][0], pose_examples[0][0])
|
132 |
-
# res_image = gr.Image(label="result image", value=init_res, type="filepath")
|
133 |
-
res_image = gr.Image(label="result image", value=cv2.imread(init_res),
|
134 |
-
type="numpy")
|
135 |
-
info_text = gr.Textbox(value="", interactive=False,
|
136 |
-
label='runtime information')
|
137 |
-
|
138 |
-
with gr.Tab('history'):
|
139 |
-
with gr.Row():
|
140 |
-
his_pose_image1 = gr.HTML()
|
141 |
-
his_res_image1 = gr.HTML()
|
142 |
-
# his_pose_image1 = gr.Image(label="pose image1", interactive=False)
|
143 |
-
# his_res_image1 = gr.Image(label="result image1", interactive=False)
|
144 |
-
|
145 |
-
with gr.Row():
|
146 |
-
his_pose_image2 = gr.HTML()
|
147 |
-
his_res_image2 = gr.HTML()
|
148 |
-
# his_pose_image2 = gr.Image(label="pose image2", interactive=False)
|
149 |
-
# his_res_image2 = gr.Image(label="result image2", interactive=False)
|
150 |
-
|
151 |
-
with gr.Row():
|
152 |
-
his_pose_image3 = gr.HTML()
|
153 |
-
his_res_image3 = gr.HTML()
|
154 |
-
# his_pose_image3 = gr.Image(label="pose image3", interactive=False)
|
155 |
-
# his_res_image3 = gr.Image(label="result image3", interactive=False)
|
156 |
-
|
157 |
-
with gr.Row():
|
158 |
-
his_pose_image4 = gr.HTML()
|
159 |
-
his_res_image4 = gr.HTML()
|
160 |
-
# his_pose_image4 = gr.Image(label="pose image4", interactive=False)
|
161 |
-
# his_res_image4 = gr.Image(label="result image4", interactive=False)
|
162 |
-
|
163 |
-
with gr.Row():
|
164 |
-
his_pose_image5 = gr.HTML()
|
165 |
-
his_res_image5 = gr.HTML()
|
166 |
-
# his_pose_image5 = gr.Image(label="pose image5", interactive=False)
|
167 |
-
# his_res_image5 = gr.Image(label="result image5", interactive=False)
|
168 |
-
|
169 |
-
|
170 |
-
run_button.click(fn=onClick, inputs=[cloth_id, pose_image, pose_id, size_slider],
|
171 |
-
outputs=[res_image, info_text], concurrency_limit=50)
|
172 |
-
|
173 |
-
pose_image.upload(fn=onUpload, inputs=[], outputs=[pose_id],)
|
174 |
-
demo.load(onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1,
|
175 |
-
his_pose_image2, his_res_image2, his_pose_image3, his_res_image3,
|
176 |
-
his_pose_image4, his_res_image4, his_pose_image5, his_res_image5,
|
177 |
-
])
|
178 |
-
|
179 |
-
if __name__ == "__main__":
|
180 |
-
|
181 |
-
demo.queue(max_size=50)
|
182 |
-
# demo.queue(concurrency_count=60)
|
183 |
-
# demo.launch(server_name='0.0.0.0', server_port=225)
|
184 |
-
demo.launch(server_name='0.0.0.0')
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|