mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 12:05:22 +00:00
some changes on api services
- exception handling added in service - new folder structure for api
This commit is contained in:
parent
fe977673be
commit
53890974ea
0
api/src/__init__.py
Normal file
0
api/src/__init__.py
Normal file
@ -1,6 +1,6 @@
|
||||
# 3rd parth dependencies
|
||||
from flask import Flask
|
||||
from routes import blueprint
|
||||
from modules.core.routes import blueprint
|
||||
|
||||
|
||||
def create_app():
|
||||
|
0
api/src/modules/core/__init__.py
Normal file
0
api/src/modules/core/__init__.py
Normal file
@ -1,5 +1,8 @@
|
||||
from flask import Blueprint, request
|
||||
import service
|
||||
from modules.core import service
|
||||
from deepface.commons.logger import Logger
|
||||
|
||||
logger = Logger(module="api/src/routes.py")
|
||||
|
||||
blueprint = Blueprint("routes", __name__)
|
||||
|
||||
@ -16,7 +19,7 @@ def represent():
|
||||
if input_args is None:
|
||||
return {"message": "empty input set passed"}
|
||||
|
||||
img_path = input_args.get("img")
|
||||
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"}
|
||||
|
||||
@ -33,6 +36,8 @@ def represent():
|
||||
align=align,
|
||||
)
|
||||
|
||||
logger.debug(obj)
|
||||
|
||||
return obj
|
||||
|
||||
|
||||
@ -43,8 +48,8 @@ def verify():
|
||||
if input_args is None:
|
||||
return {"message": "empty input set passed"}
|
||||
|
||||
img1_path = input_args.get("img1_path")
|
||||
img2_path = input_args.get("img2_path")
|
||||
img1_path = input_args.get("img1") or input_args.get("img1_path")
|
||||
img2_path = input_args.get("img2") or input_args.get("img2_path")
|
||||
|
||||
if img1_path is None:
|
||||
return {"message": "you must pass img1_path input"}
|
||||
@ -68,7 +73,7 @@ def verify():
|
||||
enforce_detection=enforce_detection,
|
||||
)
|
||||
|
||||
verification["verified"] = str(verification["verified"])
|
||||
logger.debug(verification)
|
||||
|
||||
return verification
|
||||
|
||||
@ -80,7 +85,7 @@ def analyze():
|
||||
if input_args is None:
|
||||
return {"message": "empty input set passed"}
|
||||
|
||||
img_path = input_args.get("img_path")
|
||||
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"}
|
||||
|
||||
@ -97,4 +102,6 @@ def analyze():
|
||||
align=align,
|
||||
)
|
||||
|
||||
logger.debug(demographies)
|
||||
|
||||
return demographies
|
54
api/src/modules/core/service.py
Normal file
54
api/src/modules/core/service.py
Normal file
@ -0,0 +1,54 @@
|
||||
from deepface import DeepFace
|
||||
|
||||
# pylint: disable=broad-except
|
||||
|
||||
|
||||
def represent(img_path, model_name, detector_backend, enforce_detection, align):
|
||||
try:
|
||||
result = {}
|
||||
embedding_objs = DeepFace.represent(
|
||||
img_path=img_path,
|
||||
model_name=model_name,
|
||||
detector_backend=detector_backend,
|
||||
enforce_detection=enforce_detection,
|
||||
align=align,
|
||||
)
|
||||
result["results"] = embedding_objs
|
||||
return result
|
||||
except Exception as err:
|
||||
return {"error": f"Exception while representing: {str(err)}"}, 400
|
||||
|
||||
|
||||
def verify(
|
||||
img1_path, img2_path, model_name, detector_backend, distance_metric, enforce_detection, align
|
||||
):
|
||||
try:
|
||||
obj = DeepFace.verify(
|
||||
img1_path=img1_path,
|
||||
img2_path=img2_path,
|
||||
model_name=model_name,
|
||||
detector_backend=detector_backend,
|
||||
distance_metric=distance_metric,
|
||||
align=align,
|
||||
enforce_detection=enforce_detection,
|
||||
)
|
||||
return obj
|
||||
except Exception as err:
|
||||
return {"error": f"Exception while verifying: {str(err)}"}, 400
|
||||
|
||||
|
||||
def analyze(img_path, actions, detector_backend, enforce_detection, align):
|
||||
try:
|
||||
result = {}
|
||||
demographies = DeepFace.analyze(
|
||||
img_path=img_path,
|
||||
actions=actions,
|
||||
detector_backend=detector_backend,
|
||||
enforce_detection=enforce_detection,
|
||||
align=align,
|
||||
silent=True,
|
||||
)
|
||||
result["results"] = demographies
|
||||
return result
|
||||
except Exception as err:
|
||||
return {"error": f"Exception while analyzing: {str(err)}"}, 400
|
@ -1,42 +0,0 @@
|
||||
from deepface import DeepFace
|
||||
|
||||
|
||||
def represent(img_path, model_name, detector_backend, enforce_detection, align):
|
||||
result = {}
|
||||
embedding_objs = DeepFace.represent(
|
||||
img_path=img_path,
|
||||
model_name=model_name,
|
||||
detector_backend=detector_backend,
|
||||
enforce_detection=enforce_detection,
|
||||
align=align,
|
||||
)
|
||||
result["results"] = embedding_objs
|
||||
return result
|
||||
|
||||
|
||||
def verify(
|
||||
img1_path, img2_path, model_name, detector_backend, distance_metric, enforce_detection, align
|
||||
):
|
||||
obj = DeepFace.verify(
|
||||
img1_path=img1_path,
|
||||
img2_path=img2_path,
|
||||
model_name=model_name,
|
||||
detector_backend=detector_backend,
|
||||
distance_metric=distance_metric,
|
||||
align=align,
|
||||
enforce_detection=enforce_detection,
|
||||
)
|
||||
return obj
|
||||
|
||||
|
||||
def analyze(img_path, actions, detector_backend, enforce_detection, align):
|
||||
result = {}
|
||||
demographies = DeepFace.analyze(
|
||||
img_path=img_path,
|
||||
actions=actions,
|
||||
detector_backend=detector_backend,
|
||||
enforce_detection=enforce_detection,
|
||||
align=align,
|
||||
)
|
||||
result["results"] = demographies
|
||||
return result
|
Loading…
x
Reference in New Issue
Block a user