File size: 4,726 Bytes
87d6a85
 
 
 
 
 
 
 
 
 
 
a126029
87d6a85
 
 
 
a126029
 
 
87d6a85
a126029
 
87d6a85
a126029
 
87d6a85
a126029
bd2df90
87d6a85
2dd3b91
 
 
87d6a85
a126029
 
 
 
87d6a85
 
a126029
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87d6a85
 
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
# Loading key libraries
import streamlit as st
import os
import pickle
import numpy as np
import pandas as pd
import re
from pathlib import Path
from PIL import Image
import matplotlib.pyplot as plt
import seaborn as sns
import requests




# set api endpoint
URL = 'https://bright1-sales-forecasting-api.hf.space'
API_ENDPOINT = '/predict'

# Setting the page configurations
st.set_page_config(page_title = "Prediction Forecasting", layout= "wide", initial_sidebar_state= "auto")

# Setting the page title
st.title("Grocery Store Forecasting Prediction")

# Load the saved data
df = pd.read_csv('Grocery.csv')


image1 = Image.open('images1.jpg')
image2 = Image.open('image 2.jpg')

def make_prediction(store_id, category_id, onpromotion, year,month, dayofmonth, 
                    dayofweek, dayofyear,weekofyear, quarter, is_month_start, is_month_end,
                    is_quarter_start, is_quarter_end, is_year_start, is_year_end, 
                    year_weekofyear,city, store_type, cluster):
    
    
    parameters = {
    'store_id':int(store_id), 
    'category_id':int(category_id), 
    'onpromotion' :int(onpromotion),
    'year' : int(year), 
    'month' : int(month), 
    'dayofmonth' :int(dayofmonth),
    'dayofweek' : int(dayofweek),
    'dayofyear' : int(dayofyear), 
    'weekofyear' : int(weekofyear), 
    'quarter' : int(quarter),
    'is_month_start' : int(is_month_start),
    'is_month_end' : int(is_month_end), 
    'is_quarter_start' : int(is_quarter_start), 
    'is_quarter_end' : int(is_quarter_end), 
    'is_year_start' : int(is_year_start),
    'is_year_end' : (is_year_end), 
    'year_weekofyear' : int(year_weekofyear),
    'city' : city,
    'store_type' : int(store_type), 
    'cluster': int(cluster),

    } 


    response = requests.post(url=f'{URL}{API_ENDPOINT}', params=parameters)
    sales_value = response.json()['sales']
    sales_value = round(sales_value, 4)
    return sales_value


st.image(image1, width = 700)

st.sidebar.markdown('User Input Details and Information')

store_id= st.sidebar.selectbox('store_id', options = sorted(list(df['store_id'].unique())))
category_id= st.sidebar.selectbox('categegory_id',options = sorted(list(df['category_id'].unique())))
onpromotion= st.sidebar.number_input('onpromotion', min_value= df["onpromotion"].min(), value= df["onpromotion"].min())
year = st.sidebar.selectbox('year', options = sorted(list(df['year'].unique())))
month = st.sidebar.selectbox('month', options = sorted(list(df['month'].unique())))
dayofmonth= st.sidebar.number_input('dayofmonth', min_value= df["dayofmonth"].min(), value= df["dayofmonth"].min())
dayofweek = st.sidebar.number_input('dayofweek', min_value= df["dayofweek"].min(), value= df["dayofweek"].min())
dayofyear = st.sidebar.number_input('dayofyear', min_value= df["dayofyear"].min(), value= df["dayofyear"].min())
weekofyear = st.sidebar.number_input('weekofyear', min_value= df["weekofyear"].min(), value= df["weekofyear"].min())
quarter  = st.sidebar.number_input('quarter', min_value= df["quarter"].min(), value= df["quarter"].min())
is_month_start = st.sidebar.number_input('is_month_start', min_value= df["is_month_start"].min(), value= df["is_month_start"].min())
is_month_end = st.sidebar.number_input('is_month_end', min_value= df["is_month_end"].min(), value= df["is_month_end"].min())
is_quarter_start = st.sidebar.number_input('is_quarter_start', min_value= df["is_quarter_start"].min(), value= df["is_quarter_start"].min())
is_quarter_end = st.sidebar.number_input('is_quarter_end', min_value= df["is_quarter_end"].min(), value= df["is_quarter_end"].min())
is_year_start = st.sidebar.number_input('is_year_start', min_value= df["is_year_start"].min(), value= df["is_year_start"].min())
is_year_end = st.sidebar.number_input('is_year_end', min_value= df["is_year_end"].min(), value= df["is_year_end"].min())
year_weekofyear = st.sidebar.number_input('year_weekofyear', min_value= df["year_weekofyear"].min(), value= df["year_weekofyear"].min())
city =  st.sidebar.selectbox("city:", options= sorted(set(df["city"])))
store_type=  st.sidebar.number_input('type', min_value= df["type"].min(), value= df["type"].min())
cluster = st.sidebar.selectbox('cluster', options = sorted(list(df['cluster'].unique())))



# make prediction 
sales_value = make_prediction(store_id, category_id, onpromotion, year,month, dayofmonth, 
                  dayofweek, dayofyear,weekofyear, quarter, is_month_start, is_month_end, 
                  is_quarter_start, is_quarter_end, is_year_start, is_year_end, 
                  year_weekofyear,city, store_type, cluster)

# get predicted value
if st.button('Predict'):
            st.success('The predicted target is ' + str(sales_value))