from tkinter import * from tkinter import messagebox import pickle import numpy as np from sklearn.preprocessing import StandardScaler window = Tk() window.minsize(width=600, height=600) window.config(padx=50, pady=50) window.config(background="#ffffff") window.title("Regresja") tytul = Label() tytul.config(text="Wycena wartości mieszkania na podstawie danych z serwisu otodom.pl", padx=70, pady=50, background="#ffffff") tytul.grid(column=0, row=0, columnspan=2) metraz = Label() metraz.config(text="Metraż", pady=20, background="#ffffff") metraz.grid(column=0, row=1) metraz_entry = Entry() metraz_entry.grid(column=0, row=2) pietro_entry = Entry() pietro_entry.grid(column=1, row=2) pietro = Label() pietro.config(text="Piętro", pady=20, background="#ffffff") pietro.grid(column=1, row=1) przewidywania = Label() przewidywania.config(text="Przewidywanie:", pady=20, padx=5, background="#ffffff") przewidywania.grid(column=0, row=4, sticky='e') wartosc_regresji = Label() wartosc_regresji.config(text="Wartosć przewidywana", background="#ffffff") wartosc_regresji.grid(column=1, row=4, sticky='w') model = pickle.load(open("model.pkl", 'rb')) def val_numbers(): max_metraz = 100000 max_piętro = 100 metraz = metraz_entry.get() pietro = pietro_entry.get() if metraz == "" or not metraz.isdigit() or pietro=="" or not pietro.isdigit(): messagebox.showinfo(title="Error", message=f"Please provide valid data") elif int(metraz) < 0 or int(metraz) > max_metraz or int(pietro) < 0 or int(pietro) > max_piętro: messagebox.showinfo(title="Error", message=f"Please provide numbers between 0 to 100 for floors and 0 to 100.000 for metric area.") else: confirm = messagebox.askyesno(title="Confirm", message="Do you want to start prediction?") if confirm == True: array = np.array([[int(pietro_entry.get()),float(metraz_entry.get())]]) scaler = StandardScaler() transformed_data = scaler.fit_transform(array) prediction = model.predict(transformed_data) wartosc_regresji.config(text=f'{round(prediction[0][0], 2)} PLN') start_button = Button(command=val_numbers) start_button.config(text="Start", background="#000000", foreground="#ffffff") start_button.grid(column=0, row=3, columnspan=2, sticky="s", pady=20) window.mainloop()