Skip to content

Commit

Permalink
Merge pull request serengil#1246 from serengil/feat-task-0206-cosmeti…
Browse files Browse the repository at this point in the history
…c-changes-for-docker

Feat task 0206 cosmetic changes for docker
  • Loading branch information
serengil authored Jun 2, 2024
2 parents 847fbb3 + 9d32300 commit 188e15c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ cd scripts

<p align="center"><img src="https://raw.githubusercontent.com/serengil/deepface/master/icon/deepface-api.jpg" width="90%" height="90%"></p>

Face recognition, facial attribute analysis and vector representation functions are covered in the API. You are expected to call these functions as http post methods. Default service endpoints will be `http://localhost:5000/verify` for face recognition, `http://localhost:5000/analyze` for facial attribute analysis, and `http://localhost:5000/represent` for vector representation. You can pass input images as exact image paths on your environment, base64 encoded strings or images on web. [Here](https://github.com/serengil/deepface/tree/master/deepface/api/postman), you can find a postman project to find out how these methods should be called.
Face recognition, facial attribute analysis and vector representation functions are covered in the API. You are expected to call these functions as http post methods. Default service endpoints will be `http://localhost:5005/verify` for face recognition, `http://localhost:5005/analyze` for facial attribute analysis, and `http://localhost:5005/represent` for vector representation. You can pass input images as exact image paths on your environment, base64 encoded strings or images on web. [Here](https://github.com/serengil/deepface/tree/master/deepface/api/postman), you can find a postman project to find out how these methods should be called.

**Dockerized Service** - [`Demo`](https://youtu.be/9Tk9lRQareA)

You can deploy the deepface api on a kubernetes cluster with docker. The following [shell script](https://github.com/serengil/deepface/blob/master/scripts/dockerize.sh) will serve deepface on `localhost:5000`. You need to re-configure the [Dockerfile](https://github.com/serengil/deepface/blob/master/Dockerfile) if you want to change the port. Then, even if you do not have a development environment, you will be able to consume deepface services such as verify and analyze. You can also access the inside of the docker image to run deepface related commands. Please follow the instructions in the [shell script](https://github.com/serengil/deepface/blob/master/scripts/dockerize.sh).
You can deploy the deepface api on a kubernetes cluster with docker. The following [shell script](https://github.com/serengil/deepface/blob/master/scripts/dockerize.sh) will serve deepface on `localhost:5005`. You may need to re-configure the [Dockerfile](https://github.com/serengil/deepface/blob/master/Dockerfile) if you want to apply some customization. Then, even if you do not have a development environment, you will be able to consume deepface services such as verify and analyze. You can also access the inside of the docker image to run deepface related commands. Please follow the instructions in the [shell script](https://github.com/serengil/deepface/blob/master/scripts/dockerize.sh).

```shell
cd scripts
Expand Down
6 changes: 6 additions & 0 deletions deepface/api/src/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# 3rd parth dependencies
from flask import Flask
from deepface import DeepFace
from deepface.api.src.modules.core.routes import blueprint
from deepface.commons import logger as log

logger = log.get_singletonish_logger()


def create_app():
app = Flask(__name__)
app.register_blueprint(blueprint)
logger.info(f"Welcome to DeepFace API v{DeepFace.__version__}!")
return app
3 changes: 2 additions & 1 deletion deepface/api/src/modules/core/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Blueprint, request
from deepface import DeepFace
from deepface.api.src.modules.core import service
from deepface.commons import logger as log

Expand All @@ -9,7 +10,7 @@

@blueprint.route("/")
def home():
return "<h1>Welcome to DeepFace API!</h1>"
return f"<h1>Welcome to DeepFace API v{DeepFace.__version__}!</h1>"


@blueprint.route("/represent", methods=["POST"])
Expand Down
3 changes: 2 additions & 1 deletion scripts/dockerize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ docker build -t deepface .
# docker cp ~/.deepface/weights/. <CONTAINER_ID>:/root/.deepface/weights/

# run image
docker run --net="host" deepface
# docker run --net="host" deepface
docker run -p 5005:5000 deepface

# to access the inside of docker image when it is in running status
# docker exec -it <CONTAINER_ID> /bin/sh
Expand Down
2 changes: 1 addition & 1 deletion scripts/service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ cd ../deepface/api/src
# python api.py

# run the service with gunicorn - for prod purposes
gunicorn --workers=1 --timeout=3600 --bind=0.0.0.0:5000 "app:create_app()"
gunicorn --workers=1 --timeout=3600 --bind=0.0.0.0:5005 "app:create_app()"

0 comments on commit 188e15c

Please sign in to comment.