added extract service route

This commit is contained in:
Arsalan Rabdanov 2024-09-02 13:36:19 +03:00
parent b75e37c3f6
commit 9816b8f2bd
3 changed files with 46 additions and 1 deletions

3
.gitignore vendored
View File

@ -16,4 +16,5 @@ tests/*.csv
benchmarks/results
benchmarks/outputs
benchmarks/dataset
benchmarks/lfwe
benchmarks/lfwe
venv

View File

@ -12,6 +12,29 @@ blueprint = Blueprint("routes", __name__)
def home():
return f"<h1>Welcome to DeepFace API v{DeepFace.__version__}!</h1>"
@blueprint.route("/represent", methods=["POST"])
def extract():
input_args = request.get_json()
if input_args is None:
return {"message": "empty input set passed"}
img_path = input_args.get("img") or input_args.get("img_path")
if img_path is None:
return {"message": "you must pass img_path input"}
obj = service.extract_faces(
img_path=img_path,
detector_backend=input_args.get("detector_backend", "opencv"),
enforce_detection=input_args.get("enforce_detection", True),
align=input_args.get("align", True),
anti_spoofing=input_args.get("anti_spoofing", False),
)
logger.debug(obj)
return obj
@blueprint.route("/represent", methods=["POST"])
def represent():

View File

@ -31,6 +31,27 @@ def represent(
tb_str = traceback.format_exc()
return {"error": f"Exception while representing: {str(err)} - {tb_str}"}, 400
def extract_faces(
img_path: str,
detector_backend: str,
enforce_detection: bool,
align: bool,
anti_spoofing: bool,
):
try:
result = {}
faces_objs = DeepFace.extract_faces(
img_path=img_path,
detector_backend=detector_backend,
enforce_detection=enforce_detection,
align=align,
anti_spoofing=anti_spoofing,
)
result["results"] = faces_objs
return result
except Exception as err:
tb_str = traceback.format_exc()
return {"error": f"Exception while extracting faces: {str(err)} - {tb_str}"}, 400
def verify(
img1_path: str,