import requests import json from common.logger import config version = config.get('default', 'version') if version == "local": current_photo_service_url = 'http://192.168.1.57:32678/' else: current_photo_service_url = 'http://0.0.0.0:32678/' def call_hair_infer(task_id, hair_id, hair_material_dir, infer_req, is_hr, inference_port): url = f"{current_photo_service_url}api/hair/inference" payload = json.dumps({ "task_id": task_id, "hair_id": hair_id, "hd_version_flag":is_hr, "hair_material_dir": hair_material_dir, "request_json": infer_req, "inference_port": inference_port }) headers = { 'Content-Type': 'application/json' } # print("---call infer payload:", payload) response = requests.request("POST", url, headers=headers, data=payload) # print(response.json()) return response.json() def call_hair_infer_diy(task_id, infer_req, inference_port): url = f"{current_photo_service_url}api/hair/inference_diy" payload = json.dumps({ "task_id": task_id, "request_json": infer_req, "inference_port": inference_port }) headers = { 'Content-Type': 'application/json' } # print("---call infer payload:", payload) response = requests.request("POST", url, headers=headers, data=payload) # print(response.json()) return response.json() def call_hair_enhance(img_path, mask_path, task_id, in_gender): url = "http://127.0.0.1:7393/hairEnhance/v1" payload = json.dumps({ "img_path": img_path, "mask_path": mask_path, "req_id": task_id, "gender": in_gender }) headers = { 'Content-Type': 'application/json' } # print("---call infer payload:", payload) response = requests.request("POST", url, headers=headers, data=payload) # print(response.json()) return response.json() def face_info(img_path): url = "http://127.0.0.1:7393/faceInfo/v1" payload = json.dumps({ "img": img_path, "userId": 'fff', "isLocal": True, }) headers = { 'Content-Type': 'application/json' } # print("---call infer payload:", payload) response = requests.request("POST", url, headers=headers, data=payload) print(response.json()) return response.json() def is_same(img_url1, img_url2): url = "http://127.0.0.1:7393/faceInfo/same" payload = json.dumps({ "img_url1": img_url1, "img_url2": img_url2, # "isLocal": True, }) headers = { 'Content-Type': 'application/json' } # print("---call infer payload:", payload) response = requests.request("POST", url, headers=headers, data=payload) print(response.json()) return response.json() def hair_select(img_url): url = "http://127.0.0.1:7393/hairStyle/hair_select" payload = json.dumps({ "img_url": img_url, # "isLocal": True, }) headers = { 'Content-Type': 'application/json' } # print("---call infer payload:", payload) response = requests.request("POST", url, headers=headers, data=payload) print(response.json()) return response.json() # test_url = 'https://ydapp-1317132355.cos.ap-beijing.myqcloud.com/hair_mz/images/hairstyle/fb7d7a58-3228-40f2-84a6-337088ee31e2/2023031623425988.jpg' # test_url = 'https://ydapp-1317132355.cos.ap-beijing.myqcloud.com/hair_mz/images/vaffflue12.png' # hair_select(test_url)