sai07 commited on
Commit
7f30f71
·
1 Parent(s): 2c4844f
Files changed (1) hide show
  1. app.py +237 -0
app.py ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import pandas as pd
4
+ import numpy as np
5
+
6
+ # for laptop we use the model is randomforest r2_score:-89%
7
+ def Laptop():
8
+ pipe = pickle.load(open('pipe.pkl','rb'))
9
+
10
+ df = pickle.load(open('df.pkl','rb'))
11
+
12
+ st.title('Laptop Price Predictor')
13
+
14
+ # brand
15
+ company = st.selectbox("Brand",df['Company'].unique())
16
+
17
+ # type of laptop
18
+ type = st.selectbox("Type",df['TypeName'].unique())
19
+
20
+ # ram
21
+ ram = st.selectbox("RAM(in GB)",[2,4,6,8,12,16,24,32,64])
22
+
23
+ # weight
24
+ weight = st.number_input('Weight of the Laptop')
25
+
26
+ # touchscreen
27
+ touchscreen = st.selectbox("TouchScreen",['No','Yes'])
28
+
29
+ # IPS
30
+ ips = st.selectbox('IPS',['No','Yes'])
31
+
32
+ # screen size
33
+ screen_size = st.number_input("Screen Size")
34
+
35
+ # resolution
36
+ resolution = st.selectbox('Screen Resolution',['1920x1080','1366x768','1600x900','3840x2160','3200x1800','2880x1800','2560x1600','2560x1440','2304x1440'])
37
+
38
+ #cpu
39
+ cpu = st.selectbox('CPU',df['Cpu brand'].unique())
40
+
41
+ hdd = st.selectbox('HDD(in GB)',[0,128,256,512,1024,2048])
42
+
43
+ ssd = st.selectbox('SSD(in GB)',[0,8,128,256,512,1024])
44
+
45
+ gpu = st.selectbox('GPU',df['Gpu brand'].unique())
46
+
47
+ os = st.selectbox('OS',df['os'].unique())
48
+
49
+ if st.button('Predict Price'):
50
+ # query
51
+ ppi = None
52
+ if touchscreen == 'Yes':
53
+ touchscreen = 1
54
+ else:
55
+ touchscreen = 0
56
+
57
+ if ips == 'Yes':
58
+ ips = 1
59
+ else:
60
+ ips = 0
61
+
62
+ X_res = int(resolution.split('x')[0])
63
+ Y_res = int(resolution.split('x')[1])
64
+ ppi = ((X_res**2) + (Y_res**2))**0.5/screen_size
65
+ query = np.array([company,type,ram,weight,touchscreen,ips,ppi,cpu,hdd,ssd,gpu,os])
66
+
67
+ query = query.reshape(1,12)
68
+ st.title("The predicted price of this configuration is " + str(int(np.exp(pipe.predict(query)[0]))))
69
+
70
+ # st.markdown('<b><font color="orange" size="30">The predicted price of this configuration is: </font></b>', unsafe_allow_html=True)
71
+
72
+ # st.title(str(int(np.exp(pipe.predict(query)[0]))))
73
+
74
+
75
+ def Mobile():
76
+ pipe = pickle.load(open('pipe8.pkl','rb'))
77
+
78
+ df = pickle.load(open('X_train.pkl','rb'))
79
+
80
+ st.title('Mobile Price Predictor')
81
+
82
+ # ['mobile_color', 'disp_size', 'os', 'num_cores', 'mp_speed',
83
+ # 'int_memory', 'ram', 'battery_power', 'mob_width', 'mob_height',
84
+ # 'mob_depth', 'mob_weight', 'res_dim_1', 'res_dim_2', 'p_cam_max',
85
+ # 'p_cam_count', 'f_cam_max', 'f_cam_count', '2G', '3G', '4G', '4GVOLTE',
86
+ # '5G']
87
+
88
+ # mobile color
89
+ color = st.selectbox("Color",df['mobile_color'].unique())
90
+
91
+ # disp_size
92
+ disp_size = st.number_input('Display Size(in inches)')
93
+
94
+ # os
95
+ os = st.selectbox("Operating System",sorted(df['os'].unique()))
96
+
97
+ # num_cores
98
+ num_cores = st.selectbox("No.of Cores",sorted(df['num_cores'].unique()))
99
+
100
+ # speed of cpu
101
+ mp_speed = disp_size = st.number_input('processor speed',help='2GHz processor')
102
+
103
+ # memory
104
+ int_memory = st.selectbox("Internal Memory",sorted(df['int_memory'].unique()))
105
+
106
+ # ram
107
+ ram = st.selectbox("RAM",sorted(df['ram'].unique(),reverse=True))
108
+
109
+ # battery_power
110
+ battery_power = st.selectbox("Battery",sorted(df['battery_power'].unique(),reverse=True))
111
+
112
+
113
+ # mob_width
114
+ mob_width = st.number_input('Mobile Width(mm)')
115
+
116
+ # mob_height
117
+ mob_height = st.number_input('Mobile Height(mm)')
118
+
119
+ # mob_depth
120
+ mob_depth = st.number_input('Mobile Depth(mm)')
121
+
122
+ # mob_weight
123
+ mob_weight = st.number_input('Mobile Weight')
124
+
125
+ # resolution
126
+ resolution = st.text_input("Enter Resulution")
127
+
128
+ # p_cam_max
129
+ p_cam_max = st.selectbox("Max rear camera",sorted(df['p_cam_max'].unique(),reverse=True),help='Primay Max camera')
130
+
131
+ # p_cam_count
132
+ p_cam_count = st.selectbox("Count of rear cameras",sorted(df['p_cam_count'].unique()))
133
+
134
+ # f_cam_max
135
+ f_cam_max = st.selectbox("Max front camera",sorted(df['f_cam_max'].unique()),help='Secondary Max camera')
136
+
137
+ # f_cam_count
138
+ f_cam_count = st.selectbox("Toatl no. of front cameras",[1,2],help='total no.of cameras including max camera')
139
+
140
+ # Network
141
+ network_choices = {
142
+ "2G": df['2G'].unique(),
143
+ "3G": df['3G'].unique(),
144
+ "4G": df['4G'].unique(),
145
+ "4GVOLTE": df['4GVOLTE'].unique(),
146
+ "5G": df['5G'].unique()
147
+ }
148
+
149
+ selected_network = st.selectbox("Select Network", network_choices.keys())
150
+ # selected_value = 1
151
+ if selected_network == '2G':
152
+ G2 = 1
153
+ G3 = 0
154
+ G4 = 0
155
+ G4VOLTE = 0
156
+ G5 = 0
157
+ elif selected_network == '3G':
158
+ G2 = 0
159
+ G3 = 1
160
+ G4 = 0
161
+ G4VOLTE = 0
162
+ G5 = 0
163
+ elif selected_network == '4G':
164
+ G2 = 0
165
+ G3 = 0
166
+ G4 = 1
167
+ G4VOLTE = 0
168
+ G5 = 0
169
+ elif selected_network == '4GVOLTE':
170
+ G2 = 0
171
+ G3 = 0
172
+ G4 = 0
173
+ G4VOLTE = 1
174
+ G5 = 0
175
+ else:
176
+ G2 = 0
177
+ G3 = 0
178
+ G4 = 0
179
+ G4VOLTE = 0
180
+ G5 = 1
181
+
182
+
183
+ # 'mobile_color', 'dual_sim', 'disp_size', 'os', 'num_cores', 'mp_speed',
184
+ # 'int_memory', 'ram', 'battery_power', 'mob_width', 'mob_height',
185
+ # 'mob_depth', 'mob_weight', 'res_dim_1', 'res_dim_2', 'p_cam_max',
186
+ # 'p_cam_count', 'f_cam_max', 'f_cam_count', '2G', '3G', '4G', '4GVOLTE',
187
+ # '5G'
188
+ if st.button('Predict Mobile Price'):
189
+ res_dim_1 = int(resolution.split('x')[0])
190
+ res_dim_2 = int(resolution.split('x')[1])
191
+
192
+
193
+ query = np.array([color,disp_size,os,num_cores,mp_speed,int_memory,ram,battery_power,mob_width,mob_height,mob_depth,mob_weight,res_dim_1,res_dim_2,p_cam_max,p_cam_count,f_cam_max,f_cam_count,G2,G3,G4,G4VOLTE,G5])
194
+
195
+ query = query.reshape(1,23)
196
+
197
+ st.title("The predicted price of this configuration is " + str(int(pipe.predict(query)[0])))
198
+
199
+ # pip install pandas==1.5.3
200
+
201
+
202
+
203
+ # Define two buttons with unique keys
204
+ button_clicked1 = st.button("Click For Mobile Price Predictor!", key="button1")
205
+ button_clicked2 = st.button("Click For Laptop Price Predictor!", key="button2")
206
+
207
+ # Use a session state to track whether each button has been clicked
208
+ if 'button1_click_state' not in st.session_state:
209
+ st.session_state.button1_click_state = False
210
+
211
+ if 'button2_click_state' not in st.session_state:
212
+ st.session_state.button2_click_state = False
213
+
214
+ # Check if each button was clicked
215
+ if button_clicked1:
216
+ st.session_state.button1_click_state = True
217
+ st.session_state.button2_click_state = False
218
+
219
+ if button_clicked2:
220
+ st.session_state.button2_click_state = True
221
+ st.session_state.button1_click_state = False
222
+
223
+ # Display content based on button clicks
224
+ if st.session_state.button1_click_state:
225
+ # Clear previous content
226
+ st.empty()
227
+ # Display content for the first button
228
+ Mobile()
229
+
230
+ if st.session_state.button2_click_state:
231
+ # Clear previous content
232
+ st.empty()
233
+ # Display content for the second button
234
+ Laptop()
235
+
236
+
237
+