-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainApp.py
170 lines (112 loc) · 5.21 KB
/
mainApp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# -*- coding: utf-8 -*-
"""
Main python file for Streamlit app
Author: Vukasin
"""
import streamlit as st
#import streamlit_analytics
import carClass
import predict_recommend as predict
import pandas as pd
import matplotlib.pyplot as plt
#with streamlit_analytics.track():
### Info
st.set_page_config(layout="wide")
# Set containers
container = st.container()
columns = st.columns((1,1))
with container:
st.title("Predviđanje cene polovnih automobila")
st.subheader(""" Predikcija cene polovnog automobila se izračunava na osnovu unetih parametrata u opcijama sa leve strane. """)
st.write(""" #### _Datum preuzimanja podataka: Novembar 2021. godine_ """)
#st.markdown(f'Page viewed = {s.counter}')
st.sidebar.write(""" # Specifikacije automobila """)
## Entering car specification
brand = st.sidebar.selectbox("Izaberi brend", carClass.get_brands())
model = st.sidebar.selectbox("Izaberi model", carClass.get_models(brand))
year_min, year_max = carClass.get_car_year(model)
year = st.sidebar.slider("Izaberi godište", year_min, year_max)
car_type = st.sidebar.selectbox("Izaberi karoseriju", carClass.get_car_types(brand, model))
volume = st.sidebar.selectbox("Izaberi kubikažu", carClass.get_car_volume(model, car_type))
fuel = st.sidebar.selectbox("Izaberi tip goriva", carClass.get_fuel_type(model, car_type))
mileage_min, mileage_max = carClass.get_car_mileage(model, year)
mileage_min = mileage_min+10000
mileage_max = mileage_max-10000
mileage = st.sidebar.slider('Izaberi kilometražu',mileage_min,mileage_max, step=5000)
power_ = carClass.get_engine_power(model, volume)
power = st.sidebar.selectbox('Izaberi snagu motora (KS)',power_)
emission = st.sidebar.selectbox('Izaberi emisionu klasu motora',carClass.get_emmision_class(model, year))
drive = st.sidebar.selectbox('Izaberi pogon',carClass.get_drive(model, car_type))
shift = st.sidebar.selectbox('Izaberi menjac',carClass.get_shift(model, car_type))
ac = st.sidebar.selectbox('Klima',carClass.get_ac(model))
color = st.sidebar.selectbox('Izaberi boju auta',carClass.get_colors())
material = st.sidebar.selectbox('Izaberi materijal enterijera',carClass.get_material())
age = 2021-year
avg_odo = mileage/age
km_cat = predict.convert_mileage(mileage)
## Import dataframe and encode it
predicted_price, predicted_price_p, predicted_price_m = predict.predict_price([brand, model, car_type, fuel, volume, power,emission, drive, shift, ac, color, material, avg_odo, age, km_cat])
with container:
st.header("Predviđena cena: {}€ _±{}€*_".format(predicted_price, predict.mae_calculator(predicted_price)))
st.write("_* Odnosi se na prosečnu grešku predikcije za dobijenu cenu_")
with columns[0]:
fig_year = predict.plot_predictd_years(predicted_price_p, predicted_price, predicted_price_m, year)
st.plotly_chart(fig_year)
with columns[1]:
figure = predict.plot_pie()
st.plotly_chart(figure)
st.markdown("__Napomena__: _PKPG - prosečna kilometraža po godini (Kilometraza/Starost automobila)_")
## Show similar cars
car = {'Marka' : brand,
'Model' : model,
'Godiste': year,
'Karoserija': car_type,
'Kubikaza' : volume,
'Gorivo': fuel,
'Kilometraza': mileage,
'Snaga motora' : power,
'EKM': emission,
'Pogon': drive,
'Menjac': shift,
'Klima': ac,
'Boja': color,
'Materijal enterijera': material,
'prosek_god_km': avg_odo,
'Starost': age,
'Cena': predicted_price}
#show_plot = st.sidebar.checkbox('Analiziraj cenu po godištu')
submit = st.sidebar.checkbox('Pronađi slične automobile automobile/analiziraj cenu po godištu')
#if show_plot:
# fig = predict.plot_avg(car)
# st.plotly_chart(fig, use_container_width=True)
if submit:
similar_cars = predict.recommend_car(car)
if similar_cars is not None:
# CSS to inject contained in a string
hide_table_row_index = """
<style>
tbody th {display:none}
.blank {display:none}
</style>
"""
# Inject CSS with Markdown
st.markdown(hide_table_row_index, unsafe_allow_html=True)
st.write("Pronašli smo sledeće automobile koji su slični izabranom:")
st.table(similar_cars)
#if show_plot:
similar_list = similar_cars.values.tolist()
lista_slicnih = []
for s in similar_list:
lista_slicnih.append(" | ".join([str(elem) for elem in s]))
options = st.multiselect(
'Uporedi slične automobile različitih modela',
lista_slicnih
)
options = [k.replace(" | ",",").split(",")[1] for k in options]
#(options)
fig = predict.plot_avg(car, other=options)
st.plotly_chart(fig, use_container_width=True)
else:
st.write("Nismo pronašli slične automobile, pokušajte da promenite neke od parametara")
fig = predict.plot_avg(car, other=None)
st.plotly_chart(fig, use_container_width=True)