from utils import *
def onUpload():
return ""
def onClick(cloth_id, pose_image, pose_id, size, request: gr.Request):
if pose_image is None:
return None, "no pose image found !"
# pose_id, cloth_id = pose_id['label'], cloth_id['label']
# print(pose_id, cloth_id, size, (pose_image is None), len(pose_id)>0)
if len(pose_id)>0:
res = get_result_example(cloth_id, pose_id)
print(res)
assert os.path.exists(res), res
return res, "Done! Use the pre-run results directly, the cloth size does not take effect "
else:
try:
client_ip = request.client.host
x_forwarded_for = dict(request.headers).get('x-forwarded-for')
if x_forwarded_for:
client_ip = x_forwarded_for
timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
isUpload = upload_pose_img(ApiUrl, OpenId, ApiKey, client_ip, timeId, pose_image)
if isUpload==0:
return None, "fail to upload"
elif isUpload==-1:
return None, "There is a running task already, please wait and check the history tab"
elif isUpload==-2:
return None, "can not creat task, you have exhausted free trial quota"
taskId = publicClothSwap(ApiUrl, OpenId, ApiKey, client_ip, cloth_id, timeId, size)
if taskId==0:
return None, "fail to public you task"
max_try = 1
wait_s = 30
for i in range(max_try):
time.sleep(wait_s)
state = getInfRes(ApiUrl, OpenId, ApiKey, client_ip, timeId)
if state=='stateIs-1':
return None, "task failed, it may be that no human was detected, or there may be illegal content, etc. "
elif state=='stateIs0':
return None, "task not public success"
elif len(state)>20:
return state, "task finished"
elif (not state.startswith('stateIs')):
# return None, 'task is in queue, position is '+str(state)
pass
else:
return None, state
return None, "task has been created successfully, you can refresh the page 5~15 mins latter, and check the following history tab"
except Exception as e:
print(e)
return None, "fail to create task"
def onLoad(request: gr.Request):
client_ip = request.client.host
x_forwarded_for = dict(request.headers).get('x-forwarded-for')
if x_forwarded_for:
client_ip = x_forwarded_for
his_datas = [None for _ in range(10)]
try:
infs = getAllInfs(ApiUrl, OpenId, ApiKey, client_ip)
print(client_ip, 'history infs: ', len(infs))
print(infs)
for i, inf in enumerate(infs):
if i>4: continue
pose = inf['pose']
res = inf['res']
# his_datas[i*2] = f"[pose]({pose})"+f""
# his_datas[i*2+1] = f"[res]({res})"+f""
his_datas[i*2] = f""
his_datas[i*2+1] = f"
"
time.sleep(3)
except Exception as e:
print(e)
return his_datas
cloth_examples = get_cloth_examples()
pose_examples = get_pose_examples()
# Description
title = r"""