From b6dc97e6c6726bac7edf1fe93bb4e86f37f2ccc3 Mon Sep 17 00:00:00 2001 From: kat Date: Tue, 9 Jan 2024 02:15:41 +0100 Subject: [PATCH] BLUR-21 --- blurme/pages/settings.py | 3 ++- blurme/state.py | 16 ++++++++++++++++ graphics/image_modification.py | 2 +- ml/test.py | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/blurme/pages/settings.py b/blurme/pages/settings.py index ee5ba95..c6bea08 100644 --- a/blurme/pages/settings.py +++ b/blurme/pages/settings.py @@ -2,7 +2,6 @@ import asyncio from blurme.templates import template from blurme.state import State - import reflex as rx @@ -10,6 +9,7 @@ color = "rgb(107,99,246)" @template(route="/settings", title="Zdjęcie", image = "/image-icon.png") def settings() -> rx.Component: + return rx.vstack( rx.heading("BlurMe", font_size="3em", margin_bottom="25px", background_image="linear-gradient(271.68deg, #7566fe 0.75%, #f96caf 88.52%)", background_clip="text", padding = "10px"), rx.text("Dodaj zdjęcie, które chcesz zanonimizować", font_size="1.2em"), @@ -42,6 +42,7 @@ def settings() -> rx.Component: on_click=lambda img_name=img: State.delete_image(img_name), color="rgba(255, 75, 42,255)", width = "125px"), rx.button("Anonimizuj", + on_click=lambda img_name=img: State.image_anonymization(img_name), width = "125px"), rx.button("Pobierz", on_click=lambda img_name=img: State.download_image(img_name), diff --git a/blurme/state.py b/blurme/state.py index cfb47b6..0149beb 100644 --- a/blurme/state.py +++ b/blurme/state.py @@ -1,9 +1,13 @@ """Base state for the app.""" import reflex as rx +import os from blurme import styles import asyncio +from graphics.image_modification import blur_boxes_on_image +from ml.element_detection import BoundBox, detect + class State(rx.State): """The app state.""" @@ -43,6 +47,18 @@ class State(rx.State): print(self.img) return rx.download(url=f'/{img_name}', filename=img_name) + async def image_anonymization(self, img_name: str): + if img_name in self.img: + image_path = rx.get_asset_path(img_name) + new_img_name = "anonim-" + img_name + new_image_path = rx.get_asset_path(new_img_name) + blur_boxes_on_image(image_path, detect(image_path), new_image_path) + upload_file = rx.UploadFile(file=open(new_image_path, 'rb'), filename=new_img_name) + self.delete_image(img_name) + await self.handle_upload([upload_file]) + self.img=self.img + + diff --git a/graphics/image_modification.py b/graphics/image_modification.py index 8edde89..453207a 100644 --- a/graphics/image_modification.py +++ b/graphics/image_modification.py @@ -4,7 +4,7 @@ from typing import List from PIL import Image, ImageDraw, ImageFont, ImageFilter from PIL.Image import composite -from BlurMe.ml.element_detection import BoundBox +from ml.element_detection import BoundBox DIR_PATH = os.path.dirname(os.path.realpath(__file__)) diff --git a/ml/test.py b/ml/test.py index ad99d45..4c84d74 100644 --- a/ml/test.py +++ b/ml/test.py @@ -1,7 +1,7 @@ import unittest from unittest.mock import Mock, patch from element_detection import detect, BoundBox -from BlurMe.graphics.image_modification import show_image_with_boxes +from graphics.image_modification import show_image_with_boxes class TestYourModule(unittest.TestCase):