Skip to content

Commit

Permalink
update:some-code
Browse files Browse the repository at this point in the history
  • Loading branch information
SAKURA-CAT committed Sep 5, 2024
1 parent 44772cc commit 77cf683
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 40 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,4 +32,4 @@ RUN echo "==> Clean up..." && \

EXPOSE 7860

CMD [ "python3", "app.py", "--host", "0.0.0.0", "--port", "7860"]
CMD [ "python3", "app/web.py", "--host", "0.0.0.0", "--port", "7860"]
2 changes: 1 addition & 1 deletion app.spec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ datas += collect_data_files('gradio')


a = Analysis(
['app.py'],
['app/web.py'],
pathex=[],
binaries=[],
datas=datas,
Expand Down
58 changes: 21 additions & 37 deletions scripts/api/deploy_api.py
Original file line number Diff line number Diff line change
@@ -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编码
Expand Down Expand Up @@ -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


# 透明图像添加纯色背景接口
Expand Down

0 comments on commit 77cf683

Please sign in to comment.