From 125b456743aa775b6007bf3cdd279ca9b57d2276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Henrique?= Date: Thu, 21 Sep 2023 17:57:47 -0300 Subject: [PATCH] consertos flask --- FlaskAPI/Dockerfile | 4 +-- FlaskAPI/compose.yaml | 49 ----------------------------------- FlaskAPI/controllers/image.py | 6 ++--- FlaskAPI/services/image.py | 16 +++++------- 4 files changed, 11 insertions(+), 64 deletions(-) delete mode 100644 FlaskAPI/compose.yaml diff --git a/FlaskAPI/Dockerfile b/FlaskAPI/Dockerfile index b2c6275..fc531b4 100644 --- a/FlaskAPI/Dockerfile +++ b/FlaskAPI/Dockerfile @@ -6,8 +6,6 @@ ENV PYTHONUNBUFFERED=1 WORKDIR /app -COPY . . - RUN apt-get update && apt-get install -y imagemagick && apt-get install -y wget && ls RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \ @@ -19,6 +17,8 @@ RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \ mv big-image.png ./static && \ mv video.mp4 ./static +COPY . . + RUN --mount=type=cache,target=/root/.cache/pip \ --mount=type=bind,source=requirements.txt,target=requirements.txt \ python -m pip install -r requirements.txt diff --git a/FlaskAPI/compose.yaml b/FlaskAPI/compose.yaml deleted file mode 100644 index 94e7d9c..0000000 --- a/FlaskAPI/compose.yaml +++ /dev/null @@ -1,49 +0,0 @@ -# Comments are provided throughout this file to help you get started. -# If you need more help, visit the Docker compose reference guide at -# https://docs.docker.com/compose/compose-file/ - -# Here the instructions define your application as a service called "server". -# This service is built from the Dockerfile in the current directory. -# You can add other services your application may depend on here, such as a -# database or a cache. For examples, see the Awesome Compose repository: -# https://github.com/docker/awesome-compose -services: - server: - build: - context: . - ports: - - 5000:5000 - -# The commented out section below is an example of how to define a PostgreSQL -# database that your application can use. `depends_on` tells Docker Compose to -# start the database before your application. The `db-data` volume persists the -# database data between container restarts. The `db-password` secret is used -# to set the database password. You must create `db/password.txt` and add -# a password of your choosing to it before running `docker compose up`. -# depends_on: -# db: -# condition: service_healthy -# db: -# image: postgres -# restart: always -# user: postgres -# secrets: -# - db-password -# volumes: -# - db-data:/var/lib/postgresql/data -# environment: -# - POSTGRES_DB=example -# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password -# expose: -# - 5432 -# healthcheck: -# test: [ "CMD", "pg_isready" ] -# interval: 10s -# timeout: 5s -# retries: 5 -# volumes: -# db-data: -# secrets: -# db-password: -# file: db/password.txt - diff --git a/FlaskAPI/controllers/image.py b/FlaskAPI/controllers/image.py index 2a3cad7..33e100a 100644 --- a/FlaskAPI/controllers/image.py +++ b/FlaskAPI/controllers/image.py @@ -8,8 +8,8 @@ image_service = ImageService() @image_blueprint.route('/image/blur', methods=['POST']) def blur_image(): - radius = int(request.form.get('radius')) - image = request.files.get('file') + radius = int(request.args.get('radius')) + image = request.get_data() if radius and image: return send_file(image_service.box_blur_image(image, radius), @@ -38,4 +38,4 @@ def get_big_image(): @image_blueprint.route('/image/save-big-image', methods=['POST']) def save_image(): - image_service.save_image(request.files.get('file')) + image_service.save_image(request.get_data()) diff --git a/FlaskAPI/services/image.py b/FlaskAPI/services/image.py index 6024378..f5a261f 100644 --- a/FlaskAPI/services/image.py +++ b/FlaskAPI/services/image.py @@ -28,20 +28,15 @@ def box_blur_image_separable(image, blurred_image, radius_x, radius_y): return blurred_image - -def save_image(file_stream): - with open("image.png", "wb") as file: - file.write(file_stream.read()) - file.close() - class ImageService: def __init__(self): pass def box_blur_image(self, img, radius): - with Image(filename=img) as image: - image = image.blur(radius, 0) - image = image.blur(0, radius) + with Image(blob=img) as image: + blurred_image = image.clone() + image = box_blur_image_separable(image, blurred_image, radius, 0) + image = box_blur_image_separable(image, blurred_image, 0, radius) return image def get_simple_image(self): @@ -53,4 +48,5 @@ class ImageService: return file.read() def save_image(self, img): - save_image(img) + with open("image.png", "wb") as file: + file.write(img)