Manasa1 commited on
Commit
756f8cf
·
verified ·
1 Parent(s): 97b21b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +121 -121
app.py CHANGED
@@ -1,122 +1,122 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- Created on Mon Jul 29 08:14:05 2024
4
-
5
- @author: sanath
6
- """
7
-
8
- import pickle
9
- import streamlit as st
10
- from streamlit_option_menu import option_menu
11
- import numpy as np
12
- import pandas as pd
13
- import pyarrow
14
- import xgboost as xgb
15
- from sklearn.preprocessing import LabelEncoder, StandardScaler
16
-
17
- # Print versions to ensure everything is correctly installed
18
- print(f"pyarrow version: {pyarrow.__version__}")
19
- print(f"xgboost version: {xgb.__version__}")
20
-
21
-
22
-
23
- house_model = pickle.load(open('C:/Users/sanath/Desktop/multiple disease prediction system/saved_models/HousePricePrediction.pkl','rb'))
24
- car_model = pickle.load(open('C:/Users/sanath/Desktop/multiple disease prediction system/saved_models/CarPricePrediction.pkl','rb'))
25
- bike_model = pickle.load(open('C:/Users/sanath/Desktop/multiple disease prediction system/saved_models/bikePrediction_model.pkl','rb'))
26
-
27
-
28
-
29
- with st.sidebar:
30
-
31
- selected = option_menu('Multiple Price Prediction System',
32
- ['House Price Prediction',
33
- 'Car Price Prediction',
34
- 'Bike Price Prediction'],
35
-
36
- icons = ['house','car-front-fill','bicycle'],
37
- default_index=0)
38
-
39
-
40
- if selected == 'House Price Prediction':
41
- st.title('House Price Prediction')
42
-
43
- #input
44
- medinc = st.text_input('The median income of the block group (in tens of thousands of dollars)')
45
- HouseAge = st.text_input('The median age of the houses in the block group (in years)')
46
- AveRooms = st.text_input('The average number of rooms per household in the block group')
47
- AveBedrms = st.text_input(' the average number of bedrooms per household in a given block group.')
48
- Population = st.text_input('The total number of people living in a block group.')
49
- AveOccup = st.text_input('Average number of people per household')
50
- Latitude = st.text_input('Latitude of the block group')
51
- Longitude = st.text_input('Longitude of the block group')
52
-
53
- #output
54
-
55
- # creating a button for prediction
56
-
57
- if st.button('predict house price'):
58
- # Convert input data to floats
59
- input_data = np.array([[float(medinc), float(HouseAge), float(AveRooms), float(AveBedrms),
60
- float(Population), float(AveOccup), float(Latitude), float(Longitude)]])
61
- price_prediction = house_model.predict(input_data)
62
-
63
- st.success(f'Predicted house price: ${price_prediction[0]:,.2f}')
64
-
65
-
66
-
67
-
68
- elif selected == 'Car Price Prediction':
69
- st.title('Car Price Prediction')
70
-
71
- name = st.text_input('car name')
72
- company = st.text_input('Company name')
73
- year = st.text_input('year')
74
- kms_driven = st.text_input('kilometers driven')
75
- fuel_type = st.text_input('Fuel Type')
76
-
77
- if st.button('Predict Car Price'):
78
- # Handle categorical variables with LabelEncoder
79
- label_encoder = LabelEncoder()
80
- name_encoded = label_encoder.fit_transform([name])[0]
81
- company_encoded = label_encoder.fit_transform([company])[0]
82
- fuel_type_encoded = label_encoder.fit_transform([fuel_type])[0]
83
-
84
- # Create input array
85
- inputs = np.array([[name_encoded, company_encoded, int(year), float(kms_driven), fuel_type_encoded]])
86
-
87
- # Scale the input
88
- scaler = StandardScaler()
89
- scaled_car = scaler.fit_transform(inputs)
90
-
91
- # Predict car price
92
- car_price_prediction = car_model.predict(scaled_car)
93
- st.success(f'Predicted car price: ${car_price_prediction[0]:,.2f}')
94
-
95
- elif selected == 'Bike Price Prediction':
96
- st.title('Bike Price Prediction')
97
-
98
- bike_name = st.text_input('Name of the bike')
99
- kms_driven = st.text_input('Kilometers driven')
100
- owner = st.text_input('Owner')
101
- age = st.text_input('Age of the bike')
102
- power = st.text_input('Power of the bike')
103
- brand = st.text_input('Bike brand')
104
-
105
- if st.button('Predict Bike Price'):
106
- # Handle categorical variables with LabelEncoder
107
- label_encoder = LabelEncoder()
108
- bike_name_encoded = label_encoder.fit_transform([bike_name])[0]
109
- owner_encoded = label_encoder.fit_transform([owner])[0]
110
- brand_encoded = label_encoder.fit_transform([brand])[0]
111
-
112
- # Create input array
113
- inputs = np.array([[bike_name_encoded, float(kms_driven), owner_encoded, int(age), float(power), brand_encoded]])
114
-
115
- # Scale the input
116
- scaler = StandardScaler()
117
- scaled_bike = scaler.fit_transform(inputs)
118
-
119
- # Predict bike price
120
- bike_price_prediction = bike_model.predict(scaled_bike)
121
- st.success(f'Predicted bike price: ${bike_price_prediction[0]:,.2f}')
122
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Mon Jul 29 08:14:05 2024
4
+
5
+ @author: sanath
6
+ """
7
+
8
+ import pickle
9
+ import streamlit as st
10
+ from streamlit_option_menu import option_menu
11
+ import numpy as np
12
+ import pandas as pd
13
+ import pyarrow
14
+ import xgboost as xgb
15
+ from sklearn.preprocessing import LabelEncoder, StandardScaler
16
+
17
+ # Print versions to ensure everything is correctly installed
18
+ print(f"pyarrow version: {pyarrow.__version__}")
19
+ print(f"xgboost version: {xgb.__version__}")
20
+
21
+
22
+
23
+ house_model = pickle.load(open('HousePricePrediction.pkl','rb'))
24
+ car_model = pickle.load(open('CarPricePrediction.pkl','rb'))
25
+ bike_model = pickle.load(open('bikePrediction_model.pkl','rb'))
26
+
27
+
28
+
29
+ with st.sidebar:
30
+
31
+ selected = option_menu('Multiple Price Prediction System',
32
+ ['House Price Prediction',
33
+ 'Car Price Prediction',
34
+ 'Bike Price Prediction'],
35
+
36
+ icons = ['house','car-front-fill','bicycle'],
37
+ default_index=0)
38
+
39
+
40
+ if selected == 'House Price Prediction':
41
+ st.title('House Price Prediction')
42
+
43
+ #input
44
+ medinc = st.text_input('The median income of the block group (in tens of thousands of dollars)')
45
+ HouseAge = st.text_input('The median age of the houses in the block group (in years)')
46
+ AveRooms = st.text_input('The average number of rooms per household in the block group')
47
+ AveBedrms = st.text_input(' the average number of bedrooms per household in a given block group.')
48
+ Population = st.text_input('The total number of people living in a block group.')
49
+ AveOccup = st.text_input('Average number of people per household')
50
+ Latitude = st.text_input('Latitude of the block group')
51
+ Longitude = st.text_input('Longitude of the block group')
52
+
53
+ #output
54
+
55
+ # creating a button for prediction
56
+
57
+ if st.button('predict house price'):
58
+ # Convert input data to floats
59
+ input_data = np.array([[float(medinc), float(HouseAge), float(AveRooms), float(AveBedrms),
60
+ float(Population), float(AveOccup), float(Latitude), float(Longitude)]])
61
+ price_prediction = house_model.predict(input_data)
62
+
63
+ st.success(f'Predicted house price: ${price_prediction[0]:,.2f}')
64
+
65
+
66
+
67
+
68
+ elif selected == 'Car Price Prediction':
69
+ st.title('Car Price Prediction')
70
+
71
+ name = st.text_input('car name')
72
+ company = st.text_input('Company name')
73
+ year = st.text_input('year')
74
+ kms_driven = st.text_input('kilometers driven')
75
+ fuel_type = st.text_input('Fuel Type')
76
+
77
+ if st.button('Predict Car Price'):
78
+ # Handle categorical variables with LabelEncoder
79
+ label_encoder = LabelEncoder()
80
+ name_encoded = label_encoder.fit_transform([name])[0]
81
+ company_encoded = label_encoder.fit_transform([company])[0]
82
+ fuel_type_encoded = label_encoder.fit_transform([fuel_type])[0]
83
+
84
+ # Create input array
85
+ inputs = np.array([[name_encoded, company_encoded, int(year), float(kms_driven), fuel_type_encoded]])
86
+
87
+ # Scale the input
88
+ scaler = StandardScaler()
89
+ scaled_car = scaler.fit_transform(inputs)
90
+
91
+ # Predict car price
92
+ car_price_prediction = car_model.predict(scaled_car)
93
+ st.success(f'Predicted car price: ${car_price_prediction[0]:,.2f}')
94
+
95
+ elif selected == 'Bike Price Prediction':
96
+ st.title('Bike Price Prediction')
97
+
98
+ bike_name = st.text_input('Name of the bike')
99
+ kms_driven = st.text_input('Kilometers driven')
100
+ owner = st.text_input('Owner')
101
+ age = st.text_input('Age of the bike')
102
+ power = st.text_input('Power of the bike')
103
+ brand = st.text_input('Bike brand')
104
+
105
+ if st.button('Predict Bike Price'):
106
+ # Handle categorical variables with LabelEncoder
107
+ label_encoder = LabelEncoder()
108
+ bike_name_encoded = label_encoder.fit_transform([bike_name])[0]
109
+ owner_encoded = label_encoder.fit_transform([owner])[0]
110
+ brand_encoded = label_encoder.fit_transform([brand])[0]
111
+
112
+ # Create input array
113
+ inputs = np.array([[bike_name_encoded, float(kms_driven), owner_encoded, int(age), float(power), brand_encoded]])
114
+
115
+ # Scale the input
116
+ scaler = StandardScaler()
117
+ scaled_bike = scaler.fit_transform(inputs)
118
+
119
+ # Predict bike price
120
+ bike_price_prediction = bike_model.predict(scaled_bike)
121
+ st.success(f'Predicted bike price: ${bike_price_prediction[0]:,.2f}')
122