-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsales_prediciton_app.py
78 lines (68 loc) · 1.87 KB
/
sales_prediciton_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
import streamlit as st
import pandas as pd
from xgboost import XGBRegressor
import pickle
# Load the trained XGBoost model
with open('xgb_model.pkl', 'rb') as file:
xgb_model = pickle.load(file)
# Streamlit app
def main():
# Custom favicon
st.markdown(
"""
<link rel="icon" href="data:,">
<style>
img {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
""",
unsafe_allow_html=True
)
# Custom CSS for styling
st.markdown(
"""
<style>
body {
background-color: #f4f4f4;
}
.main {
max-width: 800px;
margin: auto;
padding: 20px;
}
h1 {
color: #0066cc;
}
.btn-primary {
background-color: #0066cc;
color: #ffffff;
}
.btn-primary:hover {
background-color: #0050a5;
}
</style>
""",
unsafe_allow_html=True
)
st.title("Sales Prediction Web Application")
# User inputs
tv = st.text_input("TV Ad Spend", "")
radio = st.text_input("Radio Ad Spend", "")
newspaper = st.text_input("Newspaper Ad Spend", "")
# Make a prediction on button click
if st.button("Predict"):
try:
# Convert inputs to floats
tv = float(tv)
radio = float(radio)
newspaper = float(newspaper)
# Make a prediction using the XGBoost model
prediction = xgb_model.predict([[tv, radio, newspaper]])
st.success(f"Predicted Sales: {prediction[0]:.2f}")
except ValueError:
st.error("Please enter valid numerical values.")
if __name__ == '__main__':
main()