mieszkania5/CenaMieszkaniaDesign.py

80 lines
2.7 KiB
Python

from tkinter import *
import joblib
import pandas as pd
root = Tk()
def calculate_price():
# Get the selected values and entry input
stan = selected_stan.get()
liczba_pokoi = selected_liczba_pokoi.get()
metraz = entry1.get()
rynek = selected_rynek.get()
# Create a dictionary with the data
data = {'stan': [stan], 'l pokoi': [liczba_pokoi], 'metraż': [metraz], 'rynek': [rynek]}
# Create a DataFrame from the dictionary
X = pd.DataFrame(data)
# Load the model and make predictions
loaded_model = joblib.load('ridge_model.sav')
result = loaded_model.predict(X)
result = result / float(metraz)
# Display the result
result_label.config(text=f"Predicted Price: {result[0]:.2f} PLN")
result_label.grid(row=6, column=1, padx=10, pady=5)
root.geometry("500x500")
root.title("Mieszkaneo")
root.maxsize(900, 600)
root.config(bg="#C3DEED")
label1 = Label(root, text="Metraż", font=('Arial', 18))
label1.grid(row=0, column=0, padx=10, pady=5)
entry1 = Entry(root, font=('Arial', 18))
entry1.grid(row=1, column=0, padx=10, pady=5)
label2 = Label(root, text="Rynek", font=('Arial', 18))
label2.grid(row=0, column=1, padx=10, pady=5)
rynek_options = ["pierwotny", "wtórny"]
selected_rynek = StringVar()
selected_rynek.set(rynek_options[0])
rynek_menu = OptionMenu(root, selected_rynek, *rynek_options)
rynek_menu.config(font=('Arial', 18), bg='white', fg='black') # Kolory tła i tekstu
rynek_menu.grid(row=1, column=1, padx=10, pady=5)
label3 = Label(root, text="Stan", font=('Arial', 18))
label3.grid(row=2, column=0, padx=10, pady=5)
stan_options = ["do zamieszkania", "do wykończenia","do remontu"]
selected_stan = StringVar()
selected_stan.set(stan_options[0])
stan_menu = OptionMenu(root, selected_stan, *stan_options)
stan_menu.config(font=('Arial', 18), bg='white', fg='black') # Kolory tła i tekstu
stan_menu.grid(row=3, column=0, padx=10, pady=5)
label4 = Label(root, text="Liczba Pokoi", font=('Arial', 18))
label4.grid(row=2, column=1, padx=10, pady=5)
liczba_pokoi_options = [str(i) for i in range(1, 5)]
selected_liczba_pokoi = StringVar()
selected_liczba_pokoi.set(liczba_pokoi_options[0])
liczba_pokoi_menu = OptionMenu(root, selected_liczba_pokoi, *liczba_pokoi_options)
liczba_pokoi_menu.config(font=('Arial', 18), bg='white', fg='black') # Kolory tła i tekstu
liczba_pokoi_menu.grid(row=3, column=1, padx=10, pady=5)
button = Button(root, text="Oblicz cenę mieszkania", font=('Arial', 18), command=calculate_price)
button.config(bg='green', fg='white') # Kolory tła i tekstu
button.grid(row=4, columnspan=2, padx=10, pady=10)
result_label = Label(root, text="", font=('Arial', 18))
result_label.grid(row=5, columnspan=2, padx=10, pady=5)
root.mainloop()