selfitcamera commited on
Commit
ad38374
β€’
1 Parent(s): 8ae26fa
Files changed (1) hide show
  1. app.py +36 -34
app.py CHANGED
@@ -2,10 +2,32 @@
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 !"
@@ -16,7 +38,7 @@ def onClick(cloth_id, pose_image, pose_id, size, request: gr.Request):
16
  # print(res)
17
  assert os.path.exists(res), res
18
  # res = cv2.imread(res)
19
- return res, "Done! Use the pre-run results directly, the cloth size does not take effect "
20
  else:
21
  try:
22
  client_ip = request.client.host
@@ -26,15 +48,15 @@ def onClick(cloth_id, pose_image, pose_id, size, request: gr.Request):
26
  timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
27
  isUpload = upload_pose_img(ApiUrl, OpenId, ApiKey, client_ip, timeId, pose_image)
28
  if isUpload==0:
29
- return None, "fail to upload"
30
  elif isUpload==-1:
31
- return None, "There is a running task already, please wait and check the history tab"
32
  elif isUpload==-2:
33
- return None, "can not creat task, you have exhausted free trial quota"
34
 
35
  taskId = publicClothSwap(ApiUrl, OpenId, ApiKey, client_ip, cloth_id, timeId, size)
36
  if taskId==0:
37
- return None, "fail to public you task"
38
 
39
  max_try = 1
40
  wait_s = 30
@@ -42,20 +64,20 @@ def onClick(cloth_id, pose_image, pose_id, size, request: gr.Request):
42
  time.sleep(wait_s)
43
  state = getInfRes(ApiUrl, OpenId, ApiKey, client_ip, timeId)
44
  if state=='stateIs-1':
45
- return None, "task failed, it may be that no human was detected, or there may be illegal content, etc. "
46
  elif state=='stateIs0':
47
- return None, "task not public success"
48
  elif len(state)>20:
49
- return state, "task finished"
50
  elif (not state.startswith('stateIs')):
51
  # return None, 'task is in queue, position is '+str(state)
52
  pass
53
  else:
54
- return None, state
55
- return None, "task has been created successfully, you can refresh the page 5~15 mins latter, and check the following history tab"
56
  except Exception as e:
57
  print(e)
58
- return None, "fail to create task"
59
 
60
  def onLoad(request: gr.Request):
61
  client_ip = request.client.host
@@ -83,26 +105,6 @@ def onLoad(request: gr.Request):
83
  return his_datas
84
 
85
 
86
- cloth_examples = get_cloth_examples()
87
- pose_examples = get_pose_examples()
88
-
89
-
90
- # Description
91
- title = r"""
92
- <h1 align="center">Outfit Anyone in the Wild: Get rid of Annoying Restrictions for Virtual Try-on Task</h1>
93
- """
94
-
95
- description = r"""
96
- <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>
97
- 1. Clothing models are fixed in this demo, but you can create your own in SelfitCamera WeChat applet (for Chainese users).
98
- 2. You can upload your own pose photo, then click the run button and wait for 3~5 minutes to see the results.
99
- 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).
100
- 4. Share your try-on photo with your friends and enjoy! 😊"""
101
-
102
-
103
- css = """
104
- .gradio-container {width: 85% !important}
105
- """
106
  with gr.Blocks(css=css) as demo:
107
  # description
108
  gr.Markdown(title)
@@ -138,7 +140,7 @@ with gr.Blocks(css=css) as demo:
138
  # res_image = gr.Image(label="result image", value=None, type="numpy")
139
  # res_image = gr.Image(label="result image", value=cv2.imread(init_res),
140
  # type="numpy")
141
- gr.Markdown("If image does not display successfully after button clicked in your browser(mostly Mac+Chrome), try [this demo](https://openxlab.org.cn/apps/detail/jiangxiaoguo/OutfitAnyone-in-the-Wild) please")
142
  info_text = gr.Textbox(value="", interactive=False,
143
  label='runtime information')
144
 
@@ -164,7 +166,7 @@ with gr.Blocks(css=css) as demo:
164
  his_res_image5 = gr.HTML()
165
 
166
  run_button.click(fn=onClick, inputs=[cloth_id, pose_image, pose_id, size_slider],
167
- outputs=[res_image, info_text], concurrency_limit=50)
168
 
169
  pose_image.upload(fn=onUpload, inputs=[], outputs=[pose_id],)
170
  demo.load(onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1,
 
2
  from utils import *
3
 
4
 
5
+
6
+ cloth_examples = get_cloth_examples()
7
+ pose_examples = get_pose_examples()
8
+
9
+ # Description
10
+ title = r"""
11
+ <h1 align="center">Outfit Anyone in the Wild: Get rid of Annoying Restrictions for Virtual Try-on Task</h1>
12
+ """
13
+
14
+ description = r"""
15
+ <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>
16
+ 1. Clothing models are fixed in this demo, but you can create your own in SelfitCamera WeChat applet (for Chainese users).
17
+ 2. You can upload your own pose photo, then click the run button and wait for 3~5 minutes to see the results.
18
+ 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).
19
+ 4. Share your try-on photo with your friends and enjoy! 😊"""
20
+
21
+ css = """
22
+ .gradio-container {width: 85% !important}
23
+ """
24
+
25
+ mk_guide = "If image does not display successfully after button clicked in your browser(mostly Mac+Chrome), try [this demo](https://openxlab.org.cn/apps/detail/jiangxiaoguo/OutfitAnyone-in-the-Wild) please"
26
+
27
+
28
  def onUpload():
29
  return ""
30
 
 
31
  def onClick(cloth_id, pose_image, pose_id, size, request: gr.Request):
32
  if pose_image is None:
33
  return None, "no pose image found !"
 
38
  # print(res)
39
  assert os.path.exists(res), res
40
  # res = cv2.imread(res)
41
+ return res, "Done! Use the pre-run results directly, the cloth size does not take effect ", mk_guide
42
  else:
43
  try:
44
  client_ip = request.client.host
 
48
  timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
49
  isUpload = upload_pose_img(ApiUrl, OpenId, ApiKey, client_ip, timeId, pose_image)
50
  if isUpload==0:
51
+ return None, "fail to upload", ""
52
  elif isUpload==-1:
53
+ return None, "There is a running task already, please wait and check the history tab", ""
54
  elif isUpload==-2:
55
+ return None, "can not creat task, you have exhausted free trial quota", ""
56
 
57
  taskId = publicClothSwap(ApiUrl, OpenId, ApiKey, client_ip, cloth_id, timeId, size)
58
  if taskId==0:
59
+ return None, "fail to public you task", ""
60
 
61
  max_try = 1
62
  wait_s = 30
 
64
  time.sleep(wait_s)
65
  state = getInfRes(ApiUrl, OpenId, ApiKey, client_ip, timeId)
66
  if state=='stateIs-1':
67
+ return None, "task failed, it may be that no human was detected, or there may be illegal content, etc. ", ""
68
  elif state=='stateIs0':
69
+ return None, "task not public success", ""
70
  elif len(state)>20:
71
+ return state, "task finished", ""
72
  elif (not state.startswith('stateIs')):
73
  # return None, 'task is in queue, position is '+str(state)
74
  pass
75
  else:
76
+ return None, state, ""
77
+ return None, "task has been created successfully, you can refresh the page 5~15 mins latter, and check the following history tab", ""
78
  except Exception as e:
79
  print(e)
80
+ return None, "fail to create task", ""
81
 
82
  def onLoad(request: gr.Request):
83
  client_ip = request.client.host
 
105
  return his_datas
106
 
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  with gr.Blocks(css=css) as demo:
109
  # description
110
  gr.Markdown(title)
 
140
  # res_image = gr.Image(label="result image", value=None, type="numpy")
141
  # res_image = gr.Image(label="result image", value=cv2.imread(init_res),
142
  # type="numpy")
143
+ MK01 = gr.Markdown()
144
  info_text = gr.Textbox(value="", interactive=False,
145
  label='runtime information')
146
 
 
166
  his_res_image5 = gr.HTML()
167
 
168
  run_button.click(fn=onClick, inputs=[cloth_id, pose_image, pose_id, size_slider],
169
+ outputs=[res_image, info_text, MK01], concurrency_limit=50)
170
 
171
  pose_image.upload(fn=onUpload, inputs=[], outputs=[pose_id],)
172
  demo.load(onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1,