from utils import * cloth_examples = get_cloth_examples(hr=0) cloth_hr_examples = get_cloth_examples(hr=1) pose_examples = get_pose_examples() tip1, tip2 = get_tips() # Description title = r"""

Outfit Anyway: Best customer try-on experience ever

""" description = r""" Test results on man01.
Test results on woman01.
""" mk_guide = "" def onClick(cloth_image, pose_image, high_resolution): if pose_image is None: yield None, "no pose image found !", "" return None, "no pose image found !", "" if cloth_image is None: yield None, "no cloth image found !", "" return None, "no cloth image found !", "" pose_id = os.path.basename(pose_image).split(".")[0] cloth_id = int(os.path.basename(cloth_image).split(".")[0]) try: client_ip = '8.8.8.8' yield None, "begin to upload ", "" timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999) upload_url = upload_pose_img(ApiUrl, OpenId, ApiKey, client_ip, timeId, pose_image) # exit(0) yield None, "begin to public task ", "" # return None, "begin to public task ", "" if len(upload_url)==0: yield None, "fail to upload", "" return None, "fail to upload", "" if high_resolution: public_res = publicClothSwap(upload_url, cloth_id, is_hr=1) else: public_res = publicClothSwap(upload_url, cloth_id, is_hr=0) if public_res is None: yield None, "fail to public you task", "" return None, "fail to public you task", "" yield public_res['mid_result'], f"task is processing, task id: {public_res['id']}, {public_res['msg']}", "" max_try = 120 wait_s = 1 for i in range(max_try): time.sleep(wait_s) state = getInfRes(public_res['id']) timestamp = int(time.time() * 1000) if state is None: yield public_res['mid_result'] + f"?t={timestamp}", "task query failed,", "" elif state['status']=='PROCESSING': yield public_res['mid_result'] + f"?t={timestamp}", f"task is processing, query {i}", "" elif state['status']=='SUCCEED': yield state['output1'] + f"?t={timestamp}", f"task finished, {state['msg']}", "" return state['output1'] + f"?t={timestamp}", f"task finished, {state['msg']}", "" elif state['status']=='FAILED': yield state['mid_result'] + f"?t={timestamp}", f"task failed, {state['msg']}", "" return state['mid_result'] + f"?t={timestamp}", f"task failed, {state['msg']}", "" else: yield public_res['mid_result'] + f"?t={timestamp}", f"task is on processing, query {i}", "" return None, "no machine...", "" except Exception as e: print(e) raise e return None, "fail to create task", "" with gr.Blocks() as demo: gr.Markdown(title) gr.Markdown(description) with gr.Accordion('upload tips', open=False): with gr.Row(): gr.HTML(f"") gr.HTML(f"") with gr.Row(): with gr.Column(): cloth_image = gr.Image(value=None, interactive=False, type="filepath", label="choose a clothing") hr_example = gr.Examples(inputs=cloth_image,examples_per_page=3,examples=cloth_hr_examples, label="hight resolution clothing") example = gr.Examples(inputs=cloth_image,examples_per_page=20,examples=cloth_examples, label="normal clothing") with gr.Column(): pose_image = gr.Image(value=None, type="filepath", label="choose/upload a photo") example_pose = gr.Examples(inputs=pose_image, examples_per_page=20, examples=pose_examples) with gr.Column(): with gr.Column(): # size_slider = gr.Slider(-3, 3, value=1, interactive=True, label="clothes size") high_resolution = gr.Checkbox(value=False, label="high resolution", interactive=True) run_button = gr.Button(value="Run") info_text = gr.Textbox(value="", interactive=False, label='runtime information') res_image = gr.Image(label="result image", value=None, type="filepath") MK01 = gr.Markdown() # with gr.Tab('history'): # with gr.Row(): # 用 Row 包裹按钮 # with gr.Column(scale=0.5): # Button 占用 Row 的一半 # refresh_button = gr.Button("Refresh History", size="small") # MK02 = gr.Markdown(value="") # 示例 Markdown 内容 # # with gr.Row(): # # MK02 = gr.Markdown() # with gr.Row(): # his_pose_image1 = gr.HTML() # his_res_image1 = gr.HTML() # with gr.Row(): # his_pose_image2 = gr.HTML() # his_res_image2 = gr.HTML() # with gr.Row(): # his_pose_image3 = gr.HTML() # his_res_image3 = gr.HTML() # with gr.Row(): # his_pose_image4 = gr.HTML() # his_res_image4 = gr.HTML() # with gr.Row(): # his_pose_image5 = gr.HTML() # his_res_image5 = gr.HTML() run_button.click(fn=onClick, inputs=[cloth_image, pose_image, high_resolution], outputs=[res_image, info_text, MK01]) # refresh_button.click(fn=onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1, # his_pose_image2, his_res_image2, his_pose_image3, his_res_image3, # his_pose_image4, his_res_image4, his_pose_image5, his_res_image5, # MK02]) # demo.load(onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1, # his_pose_image2, his_res_image2, his_pose_image3, his_res_image3, # his_pose_image4, his_res_image4, his_pose_image5, his_res_image5, # MK02]) if __name__ == "__main__": demo.queue(max_size=50) # demo.queue(concurrency_count=60) # demo.launch(server_name='0.0.0.0', server_port=225) demo.launch(server_name='0.0.0.0')