-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit.py
More file actions
88 lines (68 loc) · 2.66 KB
/
streamlit.py
File metadata and controls
88 lines (68 loc) · 2.66 KB
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
import xgboost as xgb
import streamlit as st
import pandas as pd
#Loading up the Regression model we created
model = xgb.XGBRegressor()
model.load_model('xgb_model.json')
#Caching the model for faster loading
@st.cache
# Define the prediction function
def predict(carat, cut, color, clarity, depth, table, x, y, z):
#Predicting the price of the carat
if cut == 'Fair':
cut = 0
elif cut == 'Good':
cut = 1
elif cut == 'Very Good':
cut = 2
elif cut == 'Premium':
cut = 3
elif cut == 'Ideal':
cut = 4
if color == 'J':
color = 0
elif color == 'I':
color = 1
elif color == 'H':
color = 2
elif color == 'G':
color = 3
elif color == 'F':
color = 4
elif color == 'E':
color = 5
elif color == 'D':
color = 6
if clarity == 'I1':
clarity = 0
elif clarity == 'SI2':
clarity = 1
elif clarity == 'SI1':
clarity = 2
elif clarity == 'VS2':
clarity = 3
elif clarity == 'VS1':
clarity = 4
elif clarity == 'VVS2':
clarity = 5
elif clarity == 'VVS1':
clarity = 6
elif clarity == 'IF':
clarity = 7
prediction = model.predict(pd.DataFrame([[carat, cut, color, clarity, depth, table, x, y, z]], columns=['carat', 'cut', 'color', 'clarity', 'depth', 'table', 'x', 'y', 'z']))
return prediction
st.title('Diamond Price Predictor')
st.image("""https://www.thestreet.com/.image/ar_4:3%2Cc_fill%2Ccs_srgb%2Cq_auto:good%2Cw_1200/MTY4NjUwNDYyNTYzNDExNTkx/why-dominion-diamonds-second-trip-to-the-block-may-be-different.png""")
st.header('Enter the characteristics of the diamond:')
carat = st.number_input('Carat Weight:', min_value=0.1, max_value=10.0, value=1.0)
cut = st.selectbox('Cut Rating:', ['Fair', 'Good', 'Very Good', 'Premium', 'Ideal'])
color = st.selectbox('Color Rating:', ['J', 'I', 'H', 'G', 'F', 'E', 'D'])
clarity = st.selectbox('Clarity Rating:', ['I1', 'SI2', 'SI1', 'VS2', 'VS1', 'VVS2', 'VVS1', 'IF'])
depth = st.number_input('Diamond Depth Percentage:', min_value=0.1, max_value=100.0, value=1.0)
table = st.number_input('Diamond Table Percentage:', min_value=0.1, max_value=100.0, value=1.0)
x = st.number_input('Diamond Length (X) in mm:', min_value=0.1, max_value=100.0, value=1.0)
y = st.number_input('Diamond Width (Y) in mm:', min_value=0.1, max_value=100.0, value=1.0)
z = st.number_input('Diamond Height (Z) in mm:', min_value=0.1, max_value=100.0, value=1.0)
if st.button('Predict Price'):
price = predict(carat, cut, color, clarity, depth, table, x, y, z)
st.success(f'The predicted price of the diamond is ${price[0]:.2f} USD')