diff --git a/blurme/pages/settings.py b/blurme/pages/settings.py index 7d1f21e..cf9f552 100644 --- a/blurme/pages/settings.py +++ b/blurme/pages/settings.py @@ -54,6 +54,9 @@ def settings() -> rx.Component: rx.hstack(rx.button(rx.icon(tag="delete", margin_right = "8px"), " UsuĊ„", on_click=lambda img_name=img: State.delete_image(img_name), color="rgba(255, 75, 42,255)", width = "100px"), + rx.button(rx.icon(tag="edit", margin_right="8px"), " Analizuj", + on_click=lambda img_name=img: State.image_analysis(img_name), + width="130px"), rx.button(rx.icon(tag="edit", margin_right = "8px"), " Anonimizuj", on_click=lambda img_name=img: State.image_anonymization(img_name), width = "130px"), diff --git a/blurme/state.py b/blurme/state.py index 0149beb..3ee0199 100644 --- a/blurme/state.py +++ b/blurme/state.py @@ -4,8 +4,9 @@ import reflex as rx import os from blurme import styles import asyncio - +from datetime import datetime from graphics.image_modification import blur_boxes_on_image +from graphics.image_modification import show_image_with_boxes from ml.element_detection import BoundBox, detect class State(rx.State): @@ -47,20 +48,31 @@ 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): + async def image_analysis(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) + stripped_image_name = str(img_name).lstrip("analysis-").lstrip("anonim-") + image_path = rx.get_asset_path(stripped_image_name) + #timestamp = datetime.now().strftime("%Y%m%d%H%M%S%f") + new_image_name = f"analysis-{stripped_image_name}" + new_image_path = rx.get_asset_path(new_image_name) + show_image_with_boxes(image_path, detect(image_path), new_image_path) + upload_file = rx.UploadFile(file=open(new_image_path, 'rb'), filename=new_image_name) self.delete_image(img_name) await self.handle_upload([upload_file]) self.img=self.img - - - + async def image_anonymization(self, img_name: str): + if img_name in self.img: + stripped_image_name = str(img_name).lstrip("analysis-").lstrip("anonim-") + image_path = rx.get_asset_path(stripped_image_name) + #timestamp = datetime.now().strftime("%Y%m%d%H%M%S%f") + new_image_name = f"anonim-{stripped_image_name}" + new_image_path = rx.get_asset_path(new_image_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_image_name) + self.delete_image(img_name) + await self.handle_upload([upload_file]) + self.img=self.img #async def toggle_dark_mode(self):