From 8b153bc1717fbea5b30bdb287dbccbdb07e1518c Mon Sep 17 00:00:00 2001 From: alvertogit <36294057+alvertogit@users.noreply.github.com> Date: Wed, 1 Jan 2025 09:52:06 +0100 Subject: [PATCH] type hints and updated docs --- README.md | 4 ++-- app/app/__init__.py | 4 ++-- app/app/api.py | 6 +++--- app/app/model.py | 7 ++++--- app/app/templates/dlflask.html | 2 +- app/config.py | 10 ++++++---- app/server.py | 2 +- app/tests/conftest.py | 8 +++++--- app/tests/test_app.py | 8 +++++--- 9 files changed, 29 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 2bf22bd..30498bb 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ It is possible to execute tests of [Flask] microservice created with [pytest] fr ~/app# make test ... ============================= test session starts ============================== -platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0 +platform linux -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0 rootdir: /app/tests collected 2 items @@ -227,7 +227,7 @@ A POST example using [curl] from outside [Docker] container is shown below: ## CREDITS author: alvertogit -copyright: 2018-2024 +copyright: 2018-2025 [Python]: https://www.python.org/ [Flask]: https://flask.palletsprojects.com/en/1.1.x/ diff --git a/app/app/__init__.py b/app/app/__init__.py index 343e427..1158764 100644 --- a/app/app/__init__.py +++ b/app/app/__init__.py @@ -3,7 +3,7 @@ """ __author__ = "alvertogit" -__copyright__ = "Copyright 2018-2024" +__copyright__ = "Copyright 2018-2025" from config import config @@ -13,7 +13,7 @@ from .model import init_model -def create_app(config_name="default"): +def create_app(config_name: str = "default") -> Flask: """Create and configure an instance of the Flask application.""" app = Flask(__name__) app.config.from_object(config[config_name]) diff --git a/app/app/api.py b/app/app/api.py index b48bbdd..f6fda01 100644 --- a/app/app/api.py +++ b/app/app/api.py @@ -3,12 +3,12 @@ """ __author__ = "alvertogit" -__copyright__ = "Copyright 2018-2024" +__copyright__ = "Copyright 2018-2025" import io -from flask import Blueprint, jsonify, request +from flask import Blueprint, Response, jsonify, request from skimage.io import imread from .model import current_app, np, preprocess_image @@ -17,7 +17,7 @@ @api.route("/predictlabel", methods=["POST"]) -def predict(): +def predict() -> Response: """ Predict the label of an uploaded image with the Deep Learning model. diff --git a/app/app/model.py b/app/app/model.py index aa4c950..f5ed555 100644 --- a/app/app/model.py +++ b/app/app/model.py @@ -3,16 +3,17 @@ """ __author__ = "alvertogit" -__copyright__ = "Copyright 2018-2024" +__copyright__ = "Copyright 2018-2025" import numpy as np from flask import current_app from skimage import transform, util +from tensorflow.keras import Model from tensorflow.keras.models import load_model -def init_model(): +def init_model() -> Model: """ Load the pre-trained Deep Learning model. @@ -25,7 +26,7 @@ def init_model(): return model -def preprocess_image(image): +def preprocess_image(image: np.ndarray) -> np.ndarray: """ Preprocess an image for the Deep Learning model. diff --git a/app/app/templates/dlflask.html b/app/app/templates/dlflask.html index 90fcf84..d03171f 100644 --- a/app/app/templates/dlflask.html +++ b/app/app/templates/dlflask.html @@ -72,7 +72,7 @@
author: alvertogit
copyright: 2018-2024
author: alvertogit
copyright: 2018-2025