ayush-vatsal commited on
Commit
e8e9310
1 Parent(s): 97ac0ac

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +105 -0
main.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ from PIL import Image
5
+ import requests
6
+
7
+ import hopsworks
8
+ import joblib
9
+
10
+ st.set_page_config(
11
+ page_title='Car Prices Predictive Analysis',
12
+ page_icon='',
13
+ layout='wide'
14
+ )
15
+
16
+ project = hopsworks.login()
17
+ fs = project.get_feature_store()
18
+
19
+ mr = project.get_model_registry()
20
+ model = mr.get_model("car_prices", version=1)
21
+ model_dir = model.download()
22
+ model = joblib.load(model_dir + "/car_prices_model.pkl")
23
+
24
+ header = st.container()
25
+
26
+ model_train = st.container()
27
+
28
+ # mileage, engine, max_power, seats, age, seller_type, fuel_type, transmission_type
29
+ with header:
30
+ st.title("Car Prices Predictive analysis")
31
+ col_a, col_b = st.columns(2)
32
+ km = col_a.number_input("Kilometers Driven", 1000, 1000000, 10000, 1000)
33
+ engine = col_b.number_input("Engine size (in CC)", 600, 6000, 1200, 100)
34
+ power = col_a.number_input("Maximum Power in BHP", 10.0, 1000.0, 80.0, 2.0)
35
+ seats = col_b.slider("Number of Seats", 2, 10, 5, 1)
36
+ age = col_a.slider("Age of the car in years", 1, 10, 2)
37
+ seller = col_b.selectbox(
38
+ "Seller Type", ["Individual", "Dealer", "Trustmark Dealer"])
39
+ fuel = col_a.selectbox(
40
+ "Fuel Type", ["Petrol", "Diesel", "CNG", "LPG", "Electric"])
41
+ transmission = col_b.selectbox(
42
+ "Transmission Type", ["Manual", "Automatic"])
43
+
44
+ input_list = [km, 12, engine, power, seats, age, seller, fuel, transmission]
45
+
46
+ if (input_list[6] == "Dealer"):
47
+ input_list.pop(6)
48
+ input_list.insert(6, 1)
49
+ input_list.insert(7, 0)
50
+ input_list.insert(8, 0)
51
+ if (input_list[6] == "Individual"):
52
+ input_list.pop(6)
53
+ input_list.insert(6, 0)
54
+ input_list.insert(7, 1)
55
+ input_list.insert(8, 0)
56
+ if (input_list[6] == "Trustmark Dealer"):
57
+ input_list.pop(6)
58
+ input_list.insert(6, 0)
59
+ input_list.insert(7, 0)
60
+ input_list.insert(8, 1)
61
+
62
+ if (input_list[9] == "CNG"):
63
+ input_list.pop(9)
64
+ input_list.insert(9, 1)
65
+ input_list.insert(10, 0)
66
+ input_list.insert(11, 0)
67
+ input_list.insert(12, 0)
68
+ if (input_list[9] == "Diesel"):
69
+ input_list.pop(9)
70
+ input_list.insert(9, 0)
71
+ input_list.insert(10, 1)
72
+ input_list.insert(11, 0)
73
+ input_list.insert(12, 0)
74
+ if (input_list[9] == "Electric"):
75
+ input_list.pop(9)
76
+ input_list.insert(9, 0)
77
+ input_list.insert(10, 0)
78
+ input_list.insert(11, 1)
79
+ input_list.insert(12, 0)
80
+ if (input_list[9] == "Petrol"):
81
+ input_list.pop(9)
82
+ input_list.insert(9, 0)
83
+ input_list.insert(10, 0)
84
+ input_list.insert(11, 0)
85
+ input_list.insert(12, 1)
86
+
87
+ if (input_list[13] == "Automatic"):
88
+ input_list.pop(13)
89
+ input_list.insert(13, 1)
90
+ input_list.insert(14, 0)
91
+ if (input_list[13] == "Manual"):
92
+ input_list.pop(13)
93
+ input_list.insert(13, 0)
94
+ input_list.insert(14, 1)
95
+
96
+ df = pd.DataFrame(input_list)
97
+ res = model.predict(df.T)[0].round(4)
98
+
99
+ # col_but = st.columns(5)
100
+ with model_train:
101
+ disp = st.columns(5)
102
+ pred_button = disp[2].button('Evaluate price')
103
+ if pred_button:
104
+ with st.spinner():
105
+ st.write(f'#### Evaluated price of the car: ₹ {res:,.2f}')