-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
163 lines (138 loc) · 4.68 KB
/
app.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
import streamlit as st
from src.pipelines.prediction_pipeline import CustomData, PredictPipeline # Assuming this is your pipeline for prediction
# Set the page configuration
st.set_page_config(page_title="Diamond Price Prediction", page_icon="💎", layout="centered")
# Header
st.title("💎 Diamond Price Prediction 💎")
# Introduction text
st.markdown("""
Welcome to the **Diamond Price Prediction** app! Here, you can enter the details of a diamond,
and we will predict its price based on features like **Carat**, **Cut**, **Color**, **Clarity**,
and other attributes.
Just fill out the form below and click the **Predict** button to get the estimated price.
""")
# Styling the form
st.markdown("""
<style>
.form-container {
background-color: #f0f2f6;
padding: 20px;
border-radius: 10px;
}
.stButton>button {
background-color: #4CAF50;
color: white;
font-size: 18px;
border-radius: 8px;
padding: 10px 20px;
}
.stButton>button:hover {
background-color: #45a049;
}
.stInput input {
border-radius: 8px;
padding: 10px;
margin-bottom: 10px;
}
</style>
""", unsafe_allow_html=True)
# Form for the user to enter details
with st.form(key='diamond_form', clear_on_submit=True):
st.markdown('<div class="form-container">', unsafe_allow_html=True)
# Input fields with sample values (range examples)
carat = st.number_input(
'Carat (weight)',
min_value=0.0,
step=0.01,
format="%.2f",
help="Typical range: 0.2 to 5.0 carats"
)
depth = st.number_input(
'Depth (percentage)',
min_value=0.0,
step=0.01,
format="%.2f",
help="Typical range: 58% to 75%"
)
table = st.number_input(
'Table (percentage)',
min_value=0.0,
step=0.01,
format="%.2f",
help="Typical range: 50% to 70%"
)
x = st.number_input(
'X Dimension (Length in mm)',
min_value=0.0,
step=0.01,
format="%.2f",
help="Typical range: 4.0 mm to 10.0 mm"
)
y = st.number_input(
'Y Dimension (Width in mm)',
min_value=0.0,
step=0.01,
format="%.2f",
help="Typical range: 4.0 mm to 10.0 mm"
)
z = st.number_input(
'Z Dimension (Height in mm)',
min_value=0.0,
step=0.01,
format="%.2f",
help="Typical range: 2.0 mm to 6.0 mm"
)
cut = st.selectbox(
'Cut',
['Fair', 'Good', 'Very Good', 'Ideal', 'Excellent'],
help="Quality of the cut. 'Excellent' gives the best shine and brilliance."
)
color = st.selectbox(
'Color',
['D', 'E', 'F', 'G', 'H', 'I', 'J'],
help="Color scale from D (colorless) to J (light yellow or brown)."
)
clarity = st.selectbox(
'Clarity',
['SI1', 'SI2', 'VS1', 'VS2', 'VVS1', 'VVS2', 'IF', 'FL'],
help="Clarity grades from 'FL' (Flawless) to 'SI1' (Slightly Included)."
)
submit_button = st.form_submit_button(label='Predict')
st.markdown('</div>', unsafe_allow_html=True)
# When the user submits the form
if submit_button:
# Show a loading spinner while making predictions
with st.spinner('Predicting diamond price...'):
# Create the data object using user inputs
data = CustomData(
carat=carat,
depth=depth,
table=table,
x=x,
y=y,
z=z,
cut=cut,
color=color,
clarity=clarity
)
# Get the data in DataFrame format for prediction
final_new_data = data.get_data_as_dataframe()
# Initialize prediction pipeline and get the prediction
predict_pipeline = PredictPipeline()
prediction = predict_pipeline.predict(final_new_data)
# Round off the predicted price
predicted_price = round(prediction[0], 2)
# Display the result
st.success(f"💰 The predicted price of the diamond is: **${predicted_price}**")
# Additional details (optional, for a more polished result)
st.markdown("""
---
### Want to know more?
The prediction is based on a machine learning model that takes into account various attributes of a diamond such as carat, cut, color, clarity, and size. Each attribute affects the price of a diamond differently.
Have fun experimenting with different inputs and see how the predicted price changes!
""")
# Add a footer with contact info or additional details (optional)
st.markdown("""
---
**Contact us:** [info@diamondpricepredictor](mailto:info@diamondpricepredictor)
""")