BLUR-51
This commit is contained in:
parent
5e31d09001
commit
4a575c3cb6
@ -10,6 +10,7 @@ color = "rgb(107,99,246)"
|
|||||||
@template(route="/settings", title="Zdjęcie", image = "/image-icon.png")
|
@template(route="/settings", title="Zdjęcie", image = "/image-icon.png")
|
||||||
def settings() -> rx.Component:
|
def settings() -> rx.Component:
|
||||||
icon_style = {"width": "20px", "height": "30px", "margin-right": "10px"}
|
icon_style = {"width": "20px", "height": "30px", "margin-right": "10px"}
|
||||||
|
|
||||||
return rx.vstack(
|
return rx.vstack(
|
||||||
rx.wrap(
|
rx.wrap(
|
||||||
rx.hstack(
|
rx.hstack(
|
||||||
@ -19,7 +20,7 @@ def settings() -> rx.Component:
|
|||||||
background_image="linear-gradient(271.68deg, #7566fe 0.75%, #f96caf 88.52%)",
|
background_image="linear-gradient(271.68deg, #7566fe 0.75%, #f96caf 88.52%)",
|
||||||
background_clip="text", padding="5px"),
|
background_clip="text", padding="5px"),
|
||||||
rx.text("Dodaj zdjęcie, wybierz obszar i ukryj tożsamość: Anonimizacja zdjęć w mgnieniu oka – szybko, łatwo, bezpłatnie!",
|
rx.text("Dodaj zdjęcie, wybierz obszar i ukryj tożsamość: Anonimizacja zdjęć w mgnieniu oka – szybko, łatwo, bezpłatnie!",
|
||||||
font_size="1.2em", text_align="center"), width="50%", margin_left="50px", margin_right = "30px"),
|
font_size="1.2em", text_align="center"), width="50%", margin_left="50px", margin_right="30px"),
|
||||||
rx.vstack(
|
rx.vstack(
|
||||||
rx.upload(
|
rx.upload(
|
||||||
rx.vstack(
|
rx.vstack(
|
||||||
@ -32,14 +33,14 @@ def settings() -> rx.Component:
|
|||||||
),
|
),
|
||||||
border=f"1px dotted {color}",
|
border=f"1px dotted {color}",
|
||||||
padding="1em",
|
padding="1em",
|
||||||
width="100%",
|
width="120%",
|
||||||
multiple=True,
|
multiple=True,
|
||||||
accept={
|
#accept={
|
||||||
"image/png": [".png"],
|
# "image/png": [".png"],
|
||||||
"image/jpeg": [".jpg", ".jpeg"],
|
# "image/jpeg": [".jpg", ".jpeg"],
|
||||||
"image/webp": [".webp"],
|
# "image/webp": [".webp"],
|
||||||
"image/tiff": [".tif", ".tiff"],
|
# "image/tiff": [".tif", ".tiff"],
|
||||||
},
|
#},
|
||||||
margin_top="50px",
|
margin_top="50px",
|
||||||
style={"align-self": "center"},
|
style={"align-self": "center"},
|
||||||
spacing="2em",
|
spacing="2em",
|
||||||
@ -48,7 +49,7 @@ def settings() -> rx.Component:
|
|||||||
rx.box(
|
rx.box(
|
||||||
rx.button("Załaduj zdjęcie",
|
rx.button("Załaduj zdjęcie",
|
||||||
on_click=lambda: State.handle_upload(rx.upload_files()),
|
on_click=lambda: State.handle_upload(rx.upload_files()),
|
||||||
color="rgba(47, 187, 74,255)",width="90%"),
|
color="rgba(47, 187, 74,255)"),
|
||||||
rx.alert_dialog(
|
rx.alert_dialog(
|
||||||
rx.alert_dialog_overlay(
|
rx.alert_dialog_overlay(
|
||||||
rx.alert_dialog_content(
|
rx.alert_dialog_content(
|
||||||
@ -57,12 +58,26 @@ def settings() -> rx.Component:
|
|||||||
rx.alert_dialog_footer(
|
rx.alert_dialog_footer(
|
||||||
rx.button("Zamknij", color="rgba(255, 75, 42,255)",
|
rx.button("Zamknij", color="rgba(255, 75, 42,255)",
|
||||||
on_click=State.toggle_show(),
|
on_click=State.toggle_show(),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
is_open=State.show,
|
is_open=State.show,
|
||||||
),
|
),
|
||||||
|
rx.alert_dialog(
|
||||||
|
rx.alert_dialog_overlay(
|
||||||
|
rx.alert_dialog_content(
|
||||||
|
rx.alert_dialog_header("Nieprawidłowe rozszerzenie pliku"),
|
||||||
|
rx.alert_dialog_body("Dozwolone rozszerzenia plików to: png, jpg, webp, tiff."),
|
||||||
|
rx.alert_dialog_footer(
|
||||||
|
rx.button("Zamknij", color="rgba(255, 75, 42,255)",
|
||||||
|
on_click=State.toggle_extension_alert(),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
is_open=State.show_extension_alert,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import reflex as rx
|
import reflex as rx
|
||||||
import os
|
import os
|
||||||
|
import stat
|
||||||
from blurme import styles
|
from blurme import styles
|
||||||
import asyncio
|
import asyncio
|
||||||
from graphics.image_modification import blur_boxes_on_image
|
from graphics.image_modification import blur_boxes_on_image
|
||||||
@ -17,8 +18,10 @@ class State(rx.State):
|
|||||||
show: bool = False
|
show: bool = False
|
||||||
def toggle_show(self):
|
def toggle_show(self):
|
||||||
self.show = not self.show
|
self.show = not self.show
|
||||||
# Dark mode status
|
|
||||||
#dark_mode: bool = False
|
show_extension_alert: bool = False
|
||||||
|
def toggle_extension_alert(self):
|
||||||
|
self.show_extension_alert = not self.show_extension_alert
|
||||||
|
|
||||||
def change(self):
|
def change(self):
|
||||||
self.show = not (self.show)
|
self.show = not (self.show)
|
||||||
@ -30,6 +33,8 @@ class State(rx.State):
|
|||||||
files: The uploaded files.
|
files: The uploaded files.
|
||||||
"""
|
"""
|
||||||
max_files_limit = 5
|
max_files_limit = 5
|
||||||
|
acceptable_extensions = {"png", "jpg", "jpeg", "webp", "tif", "tiff"}
|
||||||
|
|
||||||
if len(self.img) + len(files) > max_files_limit:
|
if len(self.img) + len(files) > max_files_limit:
|
||||||
self.toggle_show()
|
self.toggle_show()
|
||||||
return
|
return
|
||||||
@ -39,11 +44,17 @@ class State(rx.State):
|
|||||||
upload_data = await file.read()
|
upload_data = await file.read()
|
||||||
outfile = rx.get_asset_path(file.filename)
|
outfile = rx.get_asset_path(file.filename)
|
||||||
|
|
||||||
|
extension = file.filename.split(".")[-1]
|
||||||
|
|
||||||
|
if extension.lower() not in acceptable_extensions:
|
||||||
|
self.toggle_extension_alert()
|
||||||
|
return
|
||||||
|
|
||||||
# Save the file.
|
# Save the file.
|
||||||
with open(outfile, "wb") as file_object:
|
with open(outfile, "wb") as file_object:
|
||||||
file_object.write(upload_data)
|
file_object.write(upload_data)
|
||||||
|
|
||||||
# Update the img var.
|
# Update the img var.
|
||||||
self.img.append(file.filename)
|
self.img.append(file.filename)
|
||||||
|
|
||||||
self.img = self.img
|
self.img = self.img
|
||||||
|
Loading…
Reference in New Issue
Block a user