From 77cf6838d766bb8712fe21acf312f1cf3dc9fa50 Mon Sep 17 00:00:00 2001 From: KAAANG <79990647+SAKURA-CAT@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:46:06 +0800 Subject: [PATCH] update:some-code --- Dockerfile | 5 ++-- app.spec | 2 +- scripts/api/deploy_api.py | 58 ++++++++++++++------------------------- 3 files changed, 25 insertions(+), 40 deletions(-) diff --git a/Dockerfile b/Dockerfile index b865dad..8718d21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,8 @@ WORKDIR /app COPY . . -RUN pip3 install -r requirements.txt +RUN pip3 install -r requirements.txt && \ + pip3 install -r requirements-app.txt RUN echo "==> Clean up..." && \ rm -rf ~/.cache/pip @@ -31,4 +32,4 @@ RUN echo "==> Clean up..." && \ EXPOSE 7860 -CMD [ "python3", "app.py", "--host", "0.0.0.0", "--port", "7860"] \ No newline at end of file +CMD [ "python3", "app/web.py", "--host", "0.0.0.0", "--port", "7860"] \ No newline at end of file diff --git a/app.spec b/app.spec index 29a1e54..eca7ca9 100644 --- a/app.spec +++ b/app.spec @@ -7,7 +7,7 @@ datas += collect_data_files('gradio') a = Analysis( - ['app.py'], + ['app/web.py'], pathex=[], binaries=[], datas=datas, diff --git a/scripts/api/deploy_api.py b/scripts/api/deploy_api.py index b43c97f..9d2f53d 100644 --- a/scripts/api/deploy_api.py +++ b/scripts/api/deploy_api.py @@ -1,14 +1,18 @@ from fastapi import FastAPI, UploadFile, Form import onnxruntime -from hivision.creator.face_judgement_align import IDphotos_create -from hivision.creator.layoutCreate import generate_layout_photo, generate_layout_image -from hivision.creator.vision import add_background -from utils import resize_image_to_kb_base64, hex_to_rgb +from hivision import IDCreator +from hivision.error import FaceError +from hivision.creator.layout_calculator import ( + generate_layout_photo, + generate_layout_image, +) +from hivision.utils import add_background, resize_image_to_kb_base64, hex_to_rgb import base64 import numpy as np import cv2 app = FastAPI() +creator = IDCreator() # 将图像转换为Base64编码 @@ -37,44 +41,24 @@ async def idphoto_inference( # 将字符串转为元组 size = (int(height), int(width)) - - ( - result_image_hd, - result_image_standard, - typography_arr, - typography_rotate, - _, - _, - _, - _, - status, - ) = IDphotos_create( - img, - size=size, - head_measure_ratio=head_measure_ratio, - head_height_ratio=head_height_ratio, - align=False, - beauty=False, - fd68=None, - human_sess=sess, - IS_DEBUG=False, - top_distance_max=top_distance_max, - top_distance_min=top_distance_min, - ) - - # 如果检测到人脸数量不等于1(照片无人脸 or 多人脸) - if status == 0: - result_messgae = {"status": False} - + try: + result = creator( + img, + size=size, + head_measure_ratio=head_measure_ratio, + head_height_ratio=head_height_ratio, + ) + except FaceError: + result_message = {"status": False} # 如果检测到人脸数量等于1, 则返回标准证和高清照结果(png 4通道图像) else: - result_messgae = { + result_message = { "status": True, - "image_base64_standard": numpy_2_base64(result_image_standard), - "image_base64_hd": numpy_2_base64(result_image_hd), + "image_base64_standard": numpy_2_base64(result.standard), + "image_base64_hd": numpy_2_base64(result.hd), } - return result_messgae + return result_message # 透明图像添加纯色背景接口