selfitcamera commited on
Commit
ea2f865
·
1 Parent(s): 766660f
Files changed (4) hide show
  1. __pycache__/utils.cpython-310.pyc +0 -0
  2. app.py +62 -100
  3. util_bak.py +156 -0
  4. utils.py +73 -38
__pycache__/utils.cpython-310.pyc ADDED
Binary file (4.82 kB). View file
 
app.py CHANGED
@@ -20,7 +20,7 @@ description = r"""
20
  mk_guide = ""
21
 
22
 
23
- def onClick(cloth_image, pose_image, size):
24
  if pose_image is None:
25
  yield None, "no pose image found !", ""
26
  return None, "no pose image found !", ""
@@ -30,95 +30,55 @@ def onClick(cloth_image, pose_image, size):
30
 
31
  pose_id = os.path.basename(pose_image).split(".")[0]
32
  cloth_id = int(os.path.basename(cloth_image).split(".")[0])
33
- if len(pose_id)>0:
34
- res = get_result_example(cloth_id, pose_id)
35
- # print(res)
36
- if os.path.exists(res):
37
- yield res, "Done! Use the pre-run results directly, the cloth size does not take effect ", mk_guide
38
- return res, "Done! Use the pre-run results directly, the cloth size does not take effect ", mk_guide
39
 
40
  try:
41
  client_ip = '8.8.8.8'
42
  yield None, "begin to upload ", ""
43
 
44
  timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
45
- isUpload = upload_pose_img(ApiUrl, OpenId, ApiKey, client_ip, timeId, pose_image)
 
46
  yield None, "begin to public task ", ""
 
47
 
48
- if isUpload==0:
49
  yield None, "fail to upload", ""
50
  return None, "fail to upload", ""
51
- elif isUpload==-1:
52
- yield None, "There is a running task already, please wait and check the history tab. Please remember to give us a star on github, thx~", ""
53
- return None, "There is a running task already, please wait and check the history tab. Please remember to give us a star on github, thx~", ""
54
-
55
- elif isUpload==-2:
56
- yield None, "can not creat task, you have exhausted free trial quota", ""
57
- return None, "can not creat task, you have exhausted free trial quota", ""
58
 
59
- taskId = publicClothSwap(ApiUrl, OpenId, ApiKey, client_ip, cloth_id, timeId, size)
60
- if taskId==0:
 
 
 
61
  yield None, "fail to public you task", ""
62
  return None, "fail to public you task", ""
63
 
64
- max_try = 100
65
- wait_s = 1.5
 
 
66
  for i in range(max_try):
67
  time.sleep(wait_s)
68
- state = getInfRes(ApiUrl, OpenId, ApiKey, client_ip, timeId)
69
- if state=='stateIs-1':
70
- yield None, "task failed, it may be that no human was detected, or there may be illegal content, etc. ", ""
71
- return None, "task failed, it may be that no human was detected, or there may be illegal content, etc. ", ""
72
- elif state=='stateIs0':
73
- yield None, "task not public success", ""
74
- return None, "task not public success", ""
75
- elif len(state)>20:
76
- yield state, "task finished", ""
77
- return state, "task finished", ""
78
- elif (not state.startswith('stateIs')):
79
- yield None, f"task is on processing, query {i}", ""
80
- pass
81
  else:
82
- return None, state, ""
83
- return None, "task has been created successfully, you can refresh the page 5~15 mins latter, and check the following history tab", ""
84
  except Exception as e:
85
  print(e)
86
  raise e
87
  return None, "fail to create task", ""
88
 
89
- def onLoad(request: gr.Request):
90
- client_ip = '8.8.8.8'
91
- his_datas = [None for _ in range(10)]
92
- info = ''
93
- try:
94
- infs = getAllInfs(ApiUrl, OpenId, ApiKey, client_ip)
95
- print(client_ip, 'history infs: ', len(infs))
96
- cnt = 0
97
- finish_n, fail_n, queue_n = 0, 0, 0
98
- for i, inf in enumerate(infs):
99
- if inf['state']==2:
100
- if cnt>4: continue
101
- pose, res = inf['pose'], inf['res']
102
- his_datas[cnt*2] = f"<img src=\"{pose}\" >"
103
- his_datas[cnt*2+1] = f"<img src=\"{res}\" >"
104
- finish_n += 1
105
- cnt += 1
106
- elif inf['state'] in [-1, -2, 0]:
107
- fail_n += 1
108
- elif inf['state'] in [1]:
109
- queue_n += 1
110
- info = f"{client_ip}, you have {finish_n} successed tasks, {queue_n} running tasks, {fail_n} failed tasks."
111
- if fail_n>0:
112
- info = info+" Please upload a half/full-body human image, not just a clothing image!!!"
113
- if queue_n>0:
114
- info = info+" Wait for 20s and refresh this page, successed results will display in the history tab at the bottom"
115
-
116
- except Exception as e:
117
- print(e)
118
- his_datas = his_datas + [info]
119
- return his_datas
120
-
121
-
122
  with gr.Blocks() as demo:
123
  gr.Markdown(title)
124
  gr.Markdown(description)
@@ -142,7 +102,9 @@ with gr.Blocks() as demo:
142
 
143
  with gr.Column():
144
  with gr.Column():
145
- size_slider = gr.Slider(-3, 3, value=1, interactive=True, label="clothes size")
 
 
146
  run_button = gr.Button(value="Run")
147
  info_text = gr.Textbox(value="", interactive=False,
148
  label='runtime information')
@@ -150,48 +112,48 @@ with gr.Blocks() as demo:
150
  MK01 = gr.Markdown()
151
 
152
 
153
- with gr.Tab('history'):
154
 
155
- with gr.Row(): # 用 Row 包裹按钮
156
- with gr.Column(scale=0.5): # Button 占用 Row 的一半
157
- refresh_button = gr.Button("Refresh History", size="small")
158
- MK02 = gr.Markdown(value="") # 示例 Markdown 内容
159
 
160
- # with gr.Row():
161
- # MK02 = gr.Markdown()
162
 
163
- with gr.Row():
164
- his_pose_image1 = gr.HTML()
165
- his_res_image1 = gr.HTML()
166
 
167
- with gr.Row():
168
- his_pose_image2 = gr.HTML()
169
- his_res_image2 = gr.HTML()
170
 
171
- with gr.Row():
172
- his_pose_image3 = gr.HTML()
173
- his_res_image3 = gr.HTML()
174
 
175
- with gr.Row():
176
- his_pose_image4 = gr.HTML()
177
- his_res_image4 = gr.HTML()
178
 
179
- with gr.Row():
180
- his_pose_image5 = gr.HTML()
181
- his_res_image5 = gr.HTML()
182
 
183
- run_button.click(fn=onClick, inputs=[cloth_image, pose_image, size_slider],
184
  outputs=[res_image, info_text, MK01])
185
 
186
- refresh_button.click(fn=onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1,
187
- his_pose_image2, his_res_image2, his_pose_image3, his_res_image3,
188
- his_pose_image4, his_res_image4, his_pose_image5, his_res_image5,
189
- MK02])
190
 
191
- demo.load(onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1,
192
- his_pose_image2, his_res_image2, his_pose_image3, his_res_image3,
193
- his_pose_image4, his_res_image4, his_pose_image5, his_res_image5,
194
- MK02])
195
 
196
  if __name__ == "__main__":
197
 
 
20
  mk_guide = ""
21
 
22
 
23
+ def onClick(cloth_image, pose_image, high_resolution):
24
  if pose_image is None:
25
  yield None, "no pose image found !", ""
26
  return None, "no pose image found !", ""
 
30
 
31
  pose_id = os.path.basename(pose_image).split(".")[0]
32
  cloth_id = int(os.path.basename(cloth_image).split(".")[0])
 
 
 
 
 
 
33
 
34
  try:
35
  client_ip = '8.8.8.8'
36
  yield None, "begin to upload ", ""
37
 
38
  timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
39
+ upload_url = upload_pose_img(ApiUrl, OpenId, ApiKey, client_ip, timeId, pose_image)
40
+ # exit(0)
41
  yield None, "begin to public task ", ""
42
+ # return None, "begin to public task ", ""
43
 
44
+ if len(upload_url)==0:
45
  yield None, "fail to upload", ""
46
  return None, "fail to upload", ""
 
 
 
 
 
 
 
47
 
48
+ if high_resolution:
49
+ public_res = publicClothSwap(upload_url, cloth_id, is_hr=1)
50
+ else:
51
+ public_res = publicClothSwap(upload_url, cloth_id, is_hr=0)
52
+ if public_res is None:
53
  yield None, "fail to public you task", ""
54
  return None, "fail to public you task", ""
55
 
56
+ yield public_res['mid_result'], f"task is processing, task id: {public_res['id']}, {public_res['msg']}", ""
57
+
58
+ max_try = 120
59
+ wait_s = 1
60
  for i in range(max_try):
61
  time.sleep(wait_s)
62
+ state = getInfRes(public_res['id'])
63
+ timestamp = int(time.time() * 1000)
64
+ if state is None:
65
+ yield public_res['mid_result'] + f"?t={timestamp}", "task query failed,", ""
66
+ elif state['status']=='PROCESSING':
67
+ yield public_res['mid_result'] + f"?t={timestamp}", f"task is processing, query {i}", ""
68
+ elif state['status']=='SUCCEED':
69
+ yield state['output1'] + f"?t={timestamp}", f"task finished, {state['msg']}", ""
70
+ return state['output1'] + f"?t={timestamp}", f"task finished, {state['msg']}", ""
71
+ elif state['status']=='FAILED':
72
+ yield state['mid_result'] + f"?t={timestamp}", f"task failed, {state['msg']}", ""
73
+ return state['mid_result'] + f"?t={timestamp}", f"task failed, {state['msg']}", ""
 
74
  else:
75
+ yield public_res['mid_result'] + f"?t={timestamp}", f"task is on processing, query {i}", ""
76
+ return None, "no machine...", ""
77
  except Exception as e:
78
  print(e)
79
  raise e
80
  return None, "fail to create task", ""
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  with gr.Blocks() as demo:
83
  gr.Markdown(title)
84
  gr.Markdown(description)
 
102
 
103
  with gr.Column():
104
  with gr.Column():
105
+ # size_slider = gr.Slider(-3, 3, value=1, interactive=True, label="clothes size")
106
+ high_resolution = gr.Checkbox(value=False, label="high resolution", interactive=True)
107
+
108
  run_button = gr.Button(value="Run")
109
  info_text = gr.Textbox(value="", interactive=False,
110
  label='runtime information')
 
112
  MK01 = gr.Markdown()
113
 
114
 
115
+ # with gr.Tab('history'):
116
 
117
+ # with gr.Row(): # 用 Row 包裹按钮
118
+ # with gr.Column(scale=0.5): # Button 占用 Row 的一半
119
+ # refresh_button = gr.Button("Refresh History", size="small")
120
+ # MK02 = gr.Markdown(value="") # 示例 Markdown 内容
121
 
122
+ # # with gr.Row():
123
+ # # MK02 = gr.Markdown()
124
 
125
+ # with gr.Row():
126
+ # his_pose_image1 = gr.HTML()
127
+ # his_res_image1 = gr.HTML()
128
 
129
+ # with gr.Row():
130
+ # his_pose_image2 = gr.HTML()
131
+ # his_res_image2 = gr.HTML()
132
 
133
+ # with gr.Row():
134
+ # his_pose_image3 = gr.HTML()
135
+ # his_res_image3 = gr.HTML()
136
 
137
+ # with gr.Row():
138
+ # his_pose_image4 = gr.HTML()
139
+ # his_res_image4 = gr.HTML()
140
 
141
+ # with gr.Row():
142
+ # his_pose_image5 = gr.HTML()
143
+ # his_res_image5 = gr.HTML()
144
 
145
+ run_button.click(fn=onClick, inputs=[cloth_image, pose_image, high_resolution],
146
  outputs=[res_image, info_text, MK01])
147
 
148
+ # refresh_button.click(fn=onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1,
149
+ # his_pose_image2, his_res_image2, his_pose_image3, his_res_image3,
150
+ # his_pose_image4, his_res_image4, his_pose_image5, his_res_image5,
151
+ # MK02])
152
 
153
+ # demo.load(onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1,
154
+ # his_pose_image2, his_res_image2, his_pose_image3, his_res_image3,
155
+ # his_pose_image4, his_res_image4, his_pose_image5, his_res_image5,
156
+ # MK02])
157
 
158
  if __name__ == "__main__":
159
 
util_bak.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import os
3
+ import sys
4
+ import cv2
5
+ import json
6
+ import random
7
+ import time
8
+ import requests
9
+ import func_timeout
10
+ import numpy as np
11
+ import gradio as gr
12
+
13
+
14
+ ApiUrl = "https://selfitcamera.site/public"
15
+ OpenId = 'ovB-x639B8QwdfF7kQYS9QKdK6u8'
16
+ ApiKey = 'be0b28ba433b6245ce10b7c341f'
17
+ OssUrl = "https://selfit-deploy-1256039085.cos.accelerate.myqcloud.com/"
18
+ Regions = "IndiaKorea"
19
+
20
+
21
+ proj_dir = os.path.dirname(os.path.abspath(__file__))
22
+ data_dir = os.path.join(proj_dir, 'Datas')
23
+ # data_dir = "Datas"
24
+ tmpFolder = "tmp"
25
+ os.makedirs(tmpFolder, exist_ok=True)
26
+
27
+
28
+ def get_cloth_examples(hr=0):
29
+ cloth_dir = os.path.join(data_dir, 'ClothImgs')
30
+ examples = []
31
+ files = sorted(os.listdir(cloth_dir))
32
+ hr_clothes = [507, 508]
33
+ for f in files:
34
+ if '.jpg' not in f and '.png' not in f:
35
+ continue
36
+
37
+ cloth_id = f.split(".")[0]
38
+ if int(cloth_id) in hr_clothes and hr==0:
39
+ continue
40
+ if int(cloth_id) not in hr_clothes and hr==1:
41
+ continue
42
+
43
+ cloth_path = os.path.join(cloth_dir, f)
44
+ examples.append(cloth_path)
45
+ examples = examples[::-1]
46
+ return examples
47
+
48
+ def get_pose_examples():
49
+ pose_dir = os.path.join(data_dir, 'PoseImgs')
50
+ examples = []
51
+ for f in os.listdir(pose_dir):
52
+ if '.jpg' not in f and '.png' not in f:
53
+ continue
54
+ pose_id = f.split(".")[0]
55
+ pose_path = os.path.join(pose_dir, f)
56
+ examples.append(pose_path)
57
+ return examples
58
+
59
+ def get_result_example(cloth_id, pose_id):
60
+ result_dir = os.path.join(data_dir, 'ResultImgs')
61
+ res_path = os.path.join(result_dir, f"{cloth_id}_{pose_id}.jpg")
62
+ return res_path
63
+
64
+ def get_tips():
65
+ path1 = OssUrl+'ClothData/Publics/PoseGuide/tip1.jpg'
66
+ path2 = OssUrl+'ClothData/Publics/PoseGuide/tip2.jpg'
67
+ return path1, path2
68
+
69
+ def getAllInfs(apiUrl, openId, apiKey, clientIp):
70
+ params = {'openId':openId, 'apiKey':apiKey, 'ipId':clientIp}
71
+ session = requests.session()
72
+ ret = requests.get(f"{apiUrl}/api/all_infs", params=params)
73
+ res = []
74
+ if ret.status_code==200:
75
+ if 'data' in ret.json():
76
+ records = ret.json()['data']['records']
77
+ for record in records:
78
+ res.append({'pose':OssUrl+record['body_url']+"?thumbnail/768x768>",
79
+ 'res':OssUrl+record['showUrl']+"?thumbnail/768x768>",
80
+ 'state':int(record['state'])})
81
+ # res.append({'pose':OssUrl+record['body_url'],
82
+ # 'res':OssUrl+record['showUrl']})
83
+ return res
84
+
85
+
86
+ def upload_pose_img(apiUrl, openId, apiKey, clientIp, timeId, img):
87
+ fileName = clientIp.replace(".", "")+str(timeId)+".jpg"
88
+ local_path = os.path.join(tmpFolder, fileName)
89
+ img = cv2.imread(img)
90
+ cv2.imwrite(os.path.join(tmpFolder, fileName), img)
91
+ params = {'openId':openId, 'apiKey':apiKey, 'ipId':clientIp,
92
+ 'timeId':str(timeId), 'fileName':fileName}
93
+ session = requests.session()
94
+ ret = requests.get(f"{apiUrl}/api/inf_upload", params=params)
95
+ res = 0
96
+ if ret.status_code==200:
97
+ if 'data' in ret.json():
98
+ upload_url = ret.json()['data']
99
+ if 'running' in upload_url:
100
+ res = -1 # 存在正在进行的任务
101
+ elif 'no_coin' in upload_url:
102
+ res = -2 # 该ip已经用完了quota
103
+ else:
104
+ with open(local_path, 'rb') as file:
105
+ response = requests.put(upload_url, data=file)
106
+ if response.status_code == 200:
107
+ res = 1
108
+ if os.path.exists(local_path):
109
+ os.remove(local_path)
110
+ return res
111
+
112
+
113
+ def publicClothSwap(apiUrl, openId, apiKey, clientIp, clothId, timeId, size):
114
+ params = {'openId':openId, 'apiKey':apiKey, 'ipId':clientIp,
115
+ 'timeId':timeId, 'clothId':int(clothId), 'bmi':size}
116
+ session = requests.session()
117
+ ret = requests.get(f"{apiUrl}/api/cloth_swap", params=params)
118
+ if ret.status_code==200:
119
+ if 'data' not in ret.json():
120
+ print(ret.json())
121
+ return 0
122
+ taskId = ret.json()['data']
123
+ return taskId
124
+ else:
125
+ return 0
126
+
127
+ def getInfRes(apiUrl, openId, apiKey, clientIp, timeId):
128
+ params = {'openId':openId, 'apiKey':apiKey, 'ipId':clientIp, 'timeId':timeId}
129
+ session = requests.session()
130
+ ret = requests.get(f"{apiUrl}/api/getInfRes", params=params)
131
+ if ret.status_code==200:
132
+ if 'data' not in ret.json():
133
+ print(ret.json())
134
+ return 0
135
+ return ret.json()['data']
136
+ else:
137
+ return 0
138
+
139
+ @func_timeout.func_set_timeout(10)
140
+ def check_region(ip):
141
+ session = requests.session()
142
+ ret = requests.get(f"https://webapi-pc.meitu.com/common/ip_location?ip={ip}")
143
+ for k in ret.json()['data']:
144
+ nat = ret.json()['data'][k]['nation']
145
+ if nat in Regions:
146
+ print(nat, 'invalid')
147
+ return False
148
+ else:
149
+ print(nat, 'valid')
150
+ return True
151
+ def check_region_warp(ip):
152
+ try:
153
+ return check_region(ip)
154
+ except Exception as e:
155
+ print(e)
156
+ return True
utils.py CHANGED
@@ -16,6 +16,7 @@ OpenId = 'ovB-x639B8QwdfF7kQYS9QKdK6u8'
16
  ApiKey = 'be0b28ba433b6245ce10b7c341f'
17
  OssUrl = "https://selfit-deploy-1256039085.cos.accelerate.myqcloud.com/"
18
  Regions = "IndiaKorea"
 
19
 
20
 
21
  proj_dir = os.path.dirname(os.path.abspath(__file__))
@@ -88,53 +89,87 @@ def upload_pose_img(apiUrl, openId, apiKey, clientIp, timeId, img):
88
  local_path = os.path.join(tmpFolder, fileName)
89
  img = cv2.imread(img)
90
  cv2.imwrite(os.path.join(tmpFolder, fileName), img)
91
- params = {'openId':openId, 'apiKey':apiKey, 'ipId':clientIp,
92
- 'timeId':str(timeId), 'fileName':fileName}
 
 
 
 
 
 
 
93
  session = requests.session()
94
- ret = requests.get(f"{apiUrl}/api/inf_upload", params=params)
95
- res = 0
 
 
 
 
 
96
  if ret.status_code==200:
97
- if 'data' in ret.json():
98
- upload_url = ret.json()['data']
99
- if 'running' in upload_url:
100
- res = -1 # 存在正在进行的任务
101
- elif 'no_coin' in upload_url:
102
- res = -2 # 该ip已经用完了quota
103
- else:
104
- with open(local_path, 'rb') as file:
105
- response = requests.put(upload_url, data=file)
106
- if response.status_code == 200:
107
- res = 1
108
  if os.path.exists(local_path):
109
  os.remove(local_path)
110
  return res
111
 
112
 
113
- def publicClothSwap(apiUrl, openId, apiKey, clientIp, clothId, timeId, size):
114
- params = {'openId':openId, 'apiKey':apiKey, 'ipId':clientIp,
115
- 'timeId':timeId, 'clothId':int(clothId), 'bmi':size}
116
- session = requests.session()
117
- ret = requests.get(f"{apiUrl}/api/cloth_swap", params=params)
118
- if ret.status_code==200:
119
- if 'data' not in ret.json():
120
- print(ret.json())
121
- return 0
122
- taskId = ret.json()['data']
123
- return taskId
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  else:
125
- return 0
126
-
127
- def getInfRes(apiUrl, openId, apiKey, clientIp, timeId):
128
- params = {'openId':openId, 'apiKey':apiKey, 'ipId':clientIp, 'timeId':timeId}
129
- session = requests.session()
130
- ret = requests.get(f"{apiUrl}/api/getInfRes", params=params)
131
- if ret.status_code==200:
132
- if 'data' not in ret.json():
133
- print(ret.json())
134
- return 0
135
- return ret.json()['data']
 
 
 
 
 
 
 
 
 
136
  else:
137
- return 0
138
 
139
  @func_timeout.func_set_timeout(10)
140
  def check_region(ip):
 
16
  ApiKey = 'be0b28ba433b6245ce10b7c341f'
17
  OssUrl = "https://selfit-deploy-1256039085.cos.accelerate.myqcloud.com/"
18
  Regions = "IndiaKorea"
19
+ TOKEN = os.environ['TOKEN']
20
 
21
 
22
  proj_dir = os.path.dirname(os.path.abspath(__file__))
 
89
  local_path = os.path.join(tmpFolder, fileName)
90
  img = cv2.imread(img)
91
  cv2.imwrite(os.path.join(tmpFolder, fileName), img)
92
+
93
+ json_data = {
94
+ "token": "c0e69e5d129b11efa10c525400b75156", # 使用 apiKey 作为 token
95
+ "input1": fileName,
96
+ "input2": "",
97
+ "protocol": "",
98
+ "cloud": "ali"
99
+ }
100
+
101
  session = requests.session()
102
+ ret = requests.post(
103
+ f"https://selfitapi.uk/upload",
104
+ headers={'Content-Type': 'application/json'},
105
+ json=json_data
106
+ )
107
+
108
+ res = ""
109
  if ret.status_code==200:
110
+ if 'upload1' in ret.json():
111
+ upload_url = ret.json()['upload1']
112
+ headers = {'Content-Type': 'image/jpeg'}
113
+ response = session.put(upload_url, data=open(local_path, 'rb').read(), headers=headers)
114
+ print(response.status_code)
115
+ if response.status_code == 200:
116
+ res = upload_url
 
 
 
 
117
  if os.path.exists(local_path):
118
  os.remove(local_path)
119
  return res
120
 
121
 
122
+ def publicClothSwap(image, clothId, is_hr=0):
123
+ json_data = {
124
+ "image": image,
125
+ "task_type": "11",
126
+ "param1": str(clothId),
127
+ "param2": "",
128
+ "param3": "",
129
+ "param4": str(is_hr),
130
+ "delete_if_complete": "0"
131
+ }
132
+
133
+ headers = {
134
+ 'Authorization': f'Bearer {TOKEN}',
135
+ 'Content-Type': 'application/json'
136
+ }
137
+
138
+ ret = requests.post(
139
+ 'https://selfitapi.uk/public_advton',
140
+ headers=headers,
141
+ json=json_data
142
+ )
143
+
144
+ if ret.status_code == 200:
145
+ response = ret.json()
146
+ if 'mid_result' in response and 'id' in response:
147
+ return {'mid_result': response['mid_result'], 'id': response['id'], "msg": response['msg']}
148
+ print(response)
149
+ return None
150
  else:
151
+ return None
152
+
153
+ def getInfRes(taskId):
154
+ headers = {
155
+ 'Content-Type': 'application/json'
156
+ }
157
+ json_data = {
158
+ 'id': taskId
159
+ }
160
+ ret = requests.post(
161
+ 'https://selfitapi.uk/status_advton',
162
+ headers=headers,
163
+ json=json_data
164
+ )
165
+ if ret.status_code == 200:
166
+ response = ret.json()
167
+ if 'status' in response:
168
+ return response
169
+ print(response)
170
+ return None
171
  else:
172
+ return None
173
 
174
  @func_timeout.func_set_timeout(10)
175
  def check_region(ip):