File size: 2,297 Bytes
4144ab9
 
c25cd03
 
 
 
5a56710
 
 
 
 
c25cd03
5a56710
588d3a1
 
2998f77
 
c25cd03
 
d97a5a2
c25cd03
ae33b87
c25cd03
 
 
 
 
 
 
 
 
 
 
 
5a56710
 
 
 
 
 
 
c25cd03
 
 
66191ca
 
 
 
 
e25feab
66191ca
e25feab
66191ca
 
 
 
c25cd03
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
# app.py

import streamlit as st
import pandas as pd
import numpy as np
import joblib
from datetime import datetime

# Assuming the necessary EDA functions are defined in eda.py and imported here
from eda import (average_sales_by_region, average_sales_and_profit_over_time,
                 segment_vs_region_distribution, sales_vs_profit_across_segments,
                 category_composition_for_profit_and_sales)

from prediction import make_prediction

# In your model training script and your Streamlit app script (app.py)
from transformers import UnitPriceTransformer, KMeansAndLabelTransformer, DynamicOneHotEncoder

# Load the dataset for EDA
@st.cache_data
def load_data():
    return pd.read_csv('superstore_clean.csv')

df = load_data()

# Sidebar for navigation
st.sidebar.title("Navigation")
selection = st.sidebar.radio("Go to", ["Home", "EDA", "Make a Prediction"])

if selection == "Home":
    st.title("Welcome to the Superstore Sales Dashboard")

elif selection == "EDA":
    st.title("Exploratory Data Analysis (EDA)")
    # Display EDA plots directly here or call a function that does
    average_sales_by_region(df)
    average_sales_and_profit_over_time(df)
    segment_vs_region_distribution(df)
    sales_vs_profit_across_segments(df)
    category_composition_for_profit_and_sales(df)

elif selection == "Make a Prediction":
    st.title("Make a Sales Prediction")
    with st.form("input_form"):
        # Simplify input fields based on what's actually used
        sales = st.number_input('Sales', value=100.0, format="%.2f")
        quantity = st.number_input('Quantity', value=2, format="%d")
        discount = st.number_input('Discount', value=0.0, format="%.2f")
        sub_category = st.selectbox('Sub-Category', ['Bookcases', 'Chairs', 'Labels', 'Tables', 'Storage', 'Furnishings', 'Art', 'Phones', 'Binders', 'Appliances', 'Paper', 'Accessories', 'Envelopes', 'Fasteners', 'Supplies', 'Machines', 'Copiers'])

        submitted = st.form_submit_button("Predict")

        if submitted:
            input_features = pd.DataFrame([[sales, quantity, discount, sub_category]], columns=['sales', 'quantity', 'discount', 'sub_category'])
            predicted_profit = make_prediction(input_features)
            st.write(f'Predicted Profit: {predicted_profit:.2f}')