Odstranit hatespeechapp/gui.py
This commit is contained in:
parent
b639850963
commit
70d6717600
@ -1,158 +0,0 @@
|
||||
import customtkinter as ctk
|
||||
from PIL import ImageEnhance, ImageFilter,Image
|
||||
import requests
|
||||
import tkinter as tk
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ---------- APP CONFIG ----------
|
||||
ctk.set_appearance_mode("dark")
|
||||
ctk.set_default_color_theme("dark-blue")
|
||||
|
||||
app = ctk.CTk()
|
||||
|
||||
app.geometry("1000x650")
|
||||
app.minsize(400, 400)
|
||||
app.title("Detektor nenávistného jazyka")
|
||||
app.configure(bg="transparent")
|
||||
|
||||
# ---------- BACKGROUND ----------
|
||||
bg_image_pil = Image.open("images/image.png").convert("RGB")
|
||||
bg_image_pil = bg_image_pil.filter(ImageFilter.GaussianBlur(radius=3)) # мягкий блюр
|
||||
bg_image_pil = ImageEnhance.Brightness(bg_image_pil).enhance(0.6)
|
||||
|
||||
bg_image = ctk.CTkImage(light_image=bg_image_pil, dark_image=bg_image_pil, size=(1920, 1080))
|
||||
|
||||
|
||||
bg_label = ctk.CTkLabel(app, image=bg_image, text="")
|
||||
bg_label.place(relx=0, rely=0, relwidth=1, relheight=1)
|
||||
|
||||
# ---------- HEADER ----------#1a1a1a
|
||||
header_frame = ctk.CTkFrame(app, fg_color="transparent")
|
||||
header_frame.pack(side="top", fill="x")
|
||||
|
||||
title = ctk.CTkLabel(
|
||||
header_frame,
|
||||
text="Detektor nenávistného jazyka",
|
||||
font=ctk.CTkFont(size=26, weight="bold"),
|
||||
text_color="white"
|
||||
)
|
||||
title.pack(pady=10)
|
||||
|
||||
# ---------- MAIN CARD ----------
|
||||
#1a1a1a
|
||||
|
||||
#main_card_frame = ctk.CTkFrame(app, fg_color="transparent")
|
||||
main_card_frame = ctk.CTkFrame(app, fg_color="#1a1a1a", corner_radius=25)
|
||||
main_card_frame.place(relx=0.5, rely=0.5, anchor="center", relwidth=0.9)
|
||||
|
||||
|
||||
subtitle = tk.Label(
|
||||
master=main_card_frame,
|
||||
text="Analyzujte text na nenávistný jazyk",
|
||||
font=("Arial", 28, "bold"),
|
||||
bg="#1a1a1a",
|
||||
fg="white",
|
||||
wraplength=700,
|
||||
justify="center"
|
||||
)
|
||||
subtitle.pack(fill="x", padx=20)
|
||||
|
||||
description = tk.Label(
|
||||
master=main_card_frame,
|
||||
text="Tento nástroj využíva umelú inteligenciu na identifikáciu toxického obsahu v textoch.\n"
|
||||
"Stačí zadať text a zistiť, či obsahuje nenávistný jazyk.",
|
||||
font=("Arial", 14),
|
||||
bg="#1a1a1a",
|
||||
fg="white",
|
||||
justify="center",
|
||||
wraplength=600
|
||||
)
|
||||
description.pack(fill="x", padx=20)
|
||||
|
||||
input_box = ctk.CTkTextbox(main_card_frame, height=100, corner_radius=15)
|
||||
input_box.pack(fill="x", padx=20)
|
||||
|
||||
send_btn = ctk.CTkButton(main_card_frame, text="📤 Analyzovať", command=lambda: send_request(), width=150, height=40)
|
||||
send_btn.pack(pady=(10, 30))
|
||||
|
||||
# ---------- FOOTER ----------
|
||||
footer_frame = ctk.CTkFrame(app, fg_color="transparent", corner_radius=20)
|
||||
footer_frame.pack(side="bottom", fill="x")
|
||||
|
||||
footer = ctk.CTkLabel(footer_frame, text="Created by Tetiana Mohorian", font=ctk.CTkFont(size=12), text_color="white")
|
||||
footer.pack(pady=8)
|
||||
|
||||
# ---------- ADAPTIVE PADDING ----------
|
||||
def adapt_padding(event=None):
|
||||
h = app.winfo_height()
|
||||
w = app.winfo_width()
|
||||
scale = h / 650
|
||||
|
||||
# Размеры шрифтов в зависимости от ширины окна
|
||||
if w >= 900:
|
||||
desc_font_size = 30
|
||||
subtitle_font_size = 38
|
||||
elif w >= 700:
|
||||
subtitle_font_size = 32
|
||||
desc_font_size = 20
|
||||
elif w >= 500:
|
||||
subtitle_font_size = 26
|
||||
desc_font_size = 20
|
||||
else:
|
||||
subtitle_font_size = 18
|
||||
desc_font_size = 16
|
||||
|
||||
|
||||
|
||||
subtitle.configure(font=("Arial", subtitle_font_size, "bold"))
|
||||
description.configure(font=("Arial", desc_font_size))
|
||||
|
||||
# Отступы
|
||||
subtitle.pack_configure(pady=(int(20 * scale), int(10 * scale)))
|
||||
description.pack_configure(pady=(0, int(20 * scale)))
|
||||
input_box.pack_configure(pady=(0, int(20 * scale)))
|
||||
send_btn.pack_configure(pady=(int(10 * scale), int(30 * scale)))
|
||||
|
||||
def update_wrap():
|
||||
wrap = max(int(w * 0.9), 250)
|
||||
subtitle.configure(wraplength=wrap)
|
||||
description.configure(wraplength=wrap)
|
||||
|
||||
app.after(30, update_wrap)
|
||||
|
||||
app.bind("<Configure>", adapt_padding)
|
||||
|
||||
# ---------- SEND REQUEST ----------
|
||||
def send_request():
|
||||
text = input_box.get("1.0", "end-1c").strip()
|
||||
if not text:
|
||||
subtitle.configure(text="Zadajte text", fg="red")
|
||||
description.configure(text="")
|
||||
return
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
"http://localhost:5000/api/predict",
|
||||
json={"text": text}
|
||||
)
|
||||
if response.status_code == 200:
|
||||
result = response.json()["prediction"]
|
||||
subtitle.configure(
|
||||
text=result,
|
||||
fg=("orange" if "toxický" in result.lower() else "white")
|
||||
)
|
||||
description.configure(text=f'Váš text bol: "{text}"')
|
||||
else:
|
||||
subtitle.configure(text="Chyba na serveri", fg="orange")
|
||||
description.configure(text="")
|
||||
except Exception as e:
|
||||
subtitle.configure(text=f"Chyba: {e}", fg="red")
|
||||
description.configure(text="")
|
||||
|
||||
# ---------- START ----------
|
||||
app.mainloop()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user