7sugiwa commited on
Commit
c25cd03
1 Parent(s): 0939014

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -0
app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import streamlit as st
4
+ import pandas as pd
5
+ import numpy as np
6
+ import joblib
7
+ from eda import (average_sales_by_region, average_sales_and_profit_over_time,
8
+ segment_vs_region_distribution, sales_vs_profit_across_segments,
9
+ category_composition_for_profit_and_sales)
10
+ from prediction import make_prediction
11
+
12
+ # Load the dataset for EDA
13
+ @st.cache
14
+ def load_data():
15
+ return pd.read_csv('your_dataset.csv')
16
+
17
+ df = load_data()
18
+
19
+ # Load the pipeline and model for predictions
20
+ pipeline = joblib.load('full_pipeline_with_unit_price.pkl')
21
+ model = joblib.load('best_model.pkl')
22
+
23
+ # Sidebar for navigation
24
+ st.sidebar.title("Navigation")
25
+ selection = st.sidebar.radio("Go to", ["Home", "EDA", "Make a Prediction"])
26
+
27
+ if selection == "Home":
28
+ st.title("Welcome to the Superstore Sales Dashboard")
29
+
30
+ elif selection == "EDA":
31
+ st.title("Exploratory Data Analysis (EDA)")
32
+
33
+ # Average Sales by Region
34
+ st.header("Average Sales by Region")
35
+ fig1 = average_sales_by_region(df)
36
+ st.pyplot(fig1)
37
+
38
+ # Average Sales and Profit Over Time
39
+ st.header("Average Sales and Profit Over Time")
40
+ fig2 = average_sales_and_profit_over_time(df)
41
+ st.pyplot(fig2)
42
+
43
+ # Segment vs. Region Distribution
44
+ st.header("Segment vs. Region Distribution")
45
+ fig3 = segment_vs_region_distribution(df)
46
+ st.pyplot(fig3)
47
+
48
+ # Sales vs. Profit Across Different Customer Segments
49
+ st.header("Sales vs. Profit Across Different Customer Segments")
50
+ fig4 = sales_vs_profit_across_segments(df)
51
+ st.pyplot(fig4)
52
+
53
+ # Category Composition for Profit and Sales
54
+ st.header("Category Composition for Profit and Sales")
55
+ fig5 = category_composition_for_profit_and_sales(df)
56
+ st.pyplot(fig5)
57
+
58
+ elif selection == "Make a Prediction":
59
+ st.title("Make a Sales Prediction")
60
+ # Input form
61
+ with st.form("input_form"):
62
+ row_id = st.number_input('Row ID', min_value=1, value=1, step=1)
63
+ order_id = st.text_input('Order ID')
64
+ order_date = st.date_input('Order Date')
65
+ ship_date = st.date_input('Ship Date')
66
+ ship_mode = st.selectbox('Ship Mode', ['First Class', 'Second Class', 'Standard Class', 'Same Day'])
67
+ customer_id = st.text_input('Customer ID')
68
+ customer_name = st.text_input('Customer Name')
69
+ segment = st.selectbox('Segment', ['Consumer', 'Corporate', 'Home Office'])
70
+ country = st.text_input('Country', value='United States')
71
+ city = st.text_input('City')
72
+ state = st.text_input('State')
73
+ postal_code = st.text_input('Postal Code')
74
+ region = st.selectbox('Region', ['South', 'West', 'Central', 'East'])
75
+ product_id = st.text_input('Product ID')
76
+ category = st.selectbox('Category', ['Furniture', 'Office Supplies', 'Technology'])
77
+ sub_category = st.selectbox('Sub-Category', ['Bookcases', 'Chairs', 'Labels', 'Tables', 'Storage', 'Furnishings', 'Art', 'Phones', 'Binders', 'Appliances', 'Paper', 'Accessories', 'Envelopes', 'Fasteners', 'Supplies', 'Machines', 'Copiers'])
78
+ product_name = st.text_input('Product Name')
79
+ sales = st.number_input('Sales', value=0.0, format="%.2f")
80
+ quantity = st.number_input('Quantity', value=1, format="%d")
81
+ discount = st.number_input('Discount', value=0.0, format="%.2f")
82
+ profit = st.number_input('Profit', value=0.0, format="%.2f")
83
+
84
+ submit_button = st.form_submit_button("Predict")
85
+
86
+ if submit_button:
87
+ # Construct the input DataFrame. Modify as necessary to fit the model's expected input
88
+ input_data = pd.DataFrame([[sales, quantity, discount, sub_category]],
89
+ columns=['sales', 'quantity', 'discount', 'sub_category'])
90
+
91
+ # Call prediction function
92
+ predicted_profit = make_prediction(input_data)
93
+
94
+ st.write(f'Predicted Profit: {predicted_profit:.2f}')