77 lines
2.5 KiB
Python
77 lines
2.5 KiB
Python
|
|
@app.route('/change_cloth_base64', methods=['POST'])
|
|
def change_cloth_base64():
|
|
log_message("change_cloth_base64 called")
|
|
|
|
# 获取参数
|
|
data = request.get_json()
|
|
print(f"change_cloth_base64 input data:{data}")
|
|
if not data:
|
|
return jsonify({"ret":-1, "state":-1, 'msg': 'No JSON data provided'}), 400
|
|
|
|
human_img = data.get('human_img')
|
|
cloth_img = data.get('cloth_img')
|
|
output_format = data.get('output_format')
|
|
if not output_format:
|
|
return jsonify({"state":-1, "error": "Missing 'output_format' parameter"}), 500
|
|
|
|
if not human_img or not cloth_img:
|
|
return jsonify({"ret":-1, 'msg': 'Both human_img and cloth_img are required'}), 400
|
|
|
|
human_filename = save_base64_image(human_img, 'human')
|
|
if not human_filename:
|
|
return jsonify({"ret":-1, 'msg': 'Failed to save human image'}), 500
|
|
data['human_img'] = None
|
|
|
|
human_url = f"http://117.50.44.174:{base64_test_port}/static/imgs/{human_filename}"
|
|
|
|
# 保存服装图片
|
|
cloth_filename = save_base64_image(cloth_img, 'cloth')
|
|
if not cloth_filename:
|
|
return jsonify({"ret":-1, 'msg': 'Failed to save cloth image'}), 500
|
|
data['cloth_img'] = None
|
|
|
|
cloth_url = f"http://117.50.44.174:{base64_test_port}/static/imgs/{cloth_filename}"
|
|
|
|
data["human_url"] = human_url
|
|
data["cloth_url"] = cloth_url
|
|
|
|
kuzi_img = data.get('kuzi_img')
|
|
if kuzi_img:
|
|
kuzi_filename = save_base64_image(kuzi_img, 'kuzi')
|
|
# data['kuzi_img'] = None
|
|
kuzi_url = f"http://117.50.44.174:{base64_test_port}/static/imgs/{kuzi_filename}"
|
|
data['kuzi_url'] = kuzi_url
|
|
|
|
no2 = data.get('no2')
|
|
if not no2:
|
|
data['no2'] = False
|
|
|
|
tuodi = data.get('tuodi')
|
|
if not tuodi:
|
|
data['tuodi'] = False
|
|
|
|
|
|
if not data.get('suit'):
|
|
data['suit'] = False
|
|
|
|
if data.get('cloth_len'):
|
|
print(f'客户端传入了衣服长度: {data['cloth_len']}')
|
|
else:
|
|
print('客户端传入了衣服长度,需要ai 判断')
|
|
|
|
|
|
# 在内部调用第二个HTTP请求
|
|
try:
|
|
# 调用第二个API(可以是外部服务或自己的另一个端点)
|
|
response = requests.post(f'http://127.0.0.1:{base64_test_port}/do_change_cloth', json=data)
|
|
|
|
return Response(
|
|
response=response.content,
|
|
status=response.status_code,
|
|
headers=dict(response.headers)
|
|
)
|
|
except requests.exceptions.RequestException as e:
|
|
data['second_api_error'] = str(e)
|
|
|
|
return jsonify("error"), 500 |