New app with lesser features on interface
Browse files
app.py
CHANGED
@@ -1,69 +1,57 @@
|
|
1 |
# Loading key libraries
|
2 |
import streamlit as st
|
3 |
import os
|
4 |
-
import pickle
|
5 |
import numpy as np
|
6 |
import pandas as pd
|
7 |
-
|
8 |
-
from pathlib import Path
|
9 |
from PIL import Image
|
10 |
import matplotlib.pyplot as plt
|
11 |
import seaborn as sns
|
12 |
import requests
|
13 |
-
|
14 |
-
|
15 |
|
16 |
|
17 |
# set api endpoint
|
18 |
-
URL = 'https://bright1-sales-forecasting-
|
19 |
API_ENDPOINT = '/predict'
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
# Setting the page configurations
|
22 |
st.set_page_config(page_title = "Prediction Forecasting", layout= "wide", initial_sidebar_state= "auto")
|
23 |
|
24 |
# Setting the page title
|
25 |
st.title("Grocery Store Forecasting Prediction")
|
26 |
|
27 |
-
# Load the saved data
|
28 |
-
df = pd.read_csv('Grocery.csv')
|
29 |
-
|
30 |
|
|
|
31 |
image1 = Image.open('images1.jpg')
|
32 |
-
image2 = Image.open('image 2.jpg')
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
is_quarter_start, is_quarter_end, is_year_start, is_year_end,
|
37 |
-
year_weekofyear,city, store_type, cluster):
|
38 |
|
39 |
|
40 |
parameters = {
|
41 |
'store_id':int(store_id),
|
42 |
'category_id':int(category_id),
|
43 |
'onpromotion' :int(onpromotion),
|
44 |
-
'year' : int(year),
|
45 |
-
'month' : int(month),
|
46 |
-
'dayofmonth' :int(dayofmonth),
|
47 |
-
'dayofweek' : int(dayofweek),
|
48 |
-
'dayofyear' : int(dayofyear),
|
49 |
-
'weekofyear' : int(weekofyear),
|
50 |
-
'quarter' : int(quarter),
|
51 |
-
'is_month_start' : int(is_month_start),
|
52 |
-
'is_month_end' : int(is_month_end),
|
53 |
-
'is_quarter_start' : int(is_quarter_start),
|
54 |
-
'is_quarter_end' : int(is_quarter_end),
|
55 |
-
'is_year_start' : int(is_year_start),
|
56 |
-
'is_year_end' : (is_year_end),
|
57 |
-
'year_weekofyear' : int(year_weekofyear),
|
58 |
'city' : city,
|
59 |
'store_type' : int(store_type),
|
60 |
'cluster': int(cluster),
|
|
|
61 |
|
62 |
}
|
63 |
|
64 |
-
|
65 |
response = requests.post(url=f'{URL}{API_ENDPOINT}', params=parameters)
|
|
|
66 |
sales_value = response.json()['sales']
|
|
|
67 |
sales_value = round(sales_value, 4)
|
68 |
return sales_value
|
69 |
|
@@ -72,37 +60,20 @@ st.image(image1, width = 700)
|
|
72 |
|
73 |
st.sidebar.markdown('User Input Details and Information')
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
weekofyear = st.sidebar.number_input('weekofyear', min_value= df["weekofyear"].min(), value= df["weekofyear"].min())
|
84 |
-
quarter = st.sidebar.number_input('quarter', min_value= df["quarter"].min(), value= df["quarter"].min())
|
85 |
-
is_month_start = st.sidebar.number_input('is_month_start', min_value= df["is_month_start"].min(), value= df["is_month_start"].min())
|
86 |
-
is_month_end = st.sidebar.number_input('is_month_end', min_value= df["is_month_end"].min(), value= df["is_month_end"].min())
|
87 |
-
is_quarter_start = st.sidebar.number_input('is_quarter_start', min_value= df["is_quarter_start"].min(), value= df["is_quarter_start"].min())
|
88 |
-
is_quarter_end = st.sidebar.number_input('is_quarter_end', min_value= df["is_quarter_end"].min(), value= df["is_quarter_end"].min())
|
89 |
-
is_year_start = st.sidebar.number_input('is_year_start', min_value= df["is_year_start"].min(), value= df["is_year_start"].min())
|
90 |
-
is_year_end = st.sidebar.number_input('is_year_end', min_value= df["is_year_end"].min(), value= df["is_year_end"].min())
|
91 |
-
year_weekofyear = st.sidebar.number_input('year_weekofyear', min_value= df["year_weekofyear"].min(), value= df["year_weekofyear"].min())
|
92 |
-
city = st.sidebar.selectbox("city:", options= sorted(set(df["city"])))
|
93 |
-
store_type= st.sidebar.number_input('type', min_value= df["type"].min(), value= df["type"].min())
|
94 |
-
cluster = st.sidebar.selectbox('cluster', options = sorted(list(df['cluster'].unique())))
|
95 |
-
|
96 |
-
|
97 |
|
98 |
# make prediction
|
99 |
-
sales_value = make_prediction(store_id, category_id, onpromotion,
|
100 |
-
dayofweek, dayofyear,weekofyear, quarter, is_month_start, is_month_end,
|
101 |
-
is_quarter_start, is_quarter_end, is_year_start, is_year_end,
|
102 |
-
year_weekofyear,city, store_type, cluster)
|
103 |
|
104 |
# get predicted value
|
105 |
-
if st.button('Predict'):
|
106 |
st.success('The predicted target is ' + str(sales_value))
|
107 |
|
108 |
|
|
|
1 |
# Loading key libraries
|
2 |
import streamlit as st
|
3 |
import os
|
|
|
4 |
import numpy as np
|
5 |
import pandas as pd
|
6 |
+
|
|
|
7 |
from PIL import Image
|
8 |
import matplotlib.pyplot as plt
|
9 |
import seaborn as sns
|
10 |
import requests
|
11 |
+
import datetime
|
|
|
12 |
|
13 |
|
14 |
# set api endpoint
|
15 |
+
URL = 'https://bright1-sales-forecasting-ap1-2.hf.space'
|
16 |
API_ENDPOINT = '/predict'
|
17 |
|
18 |
+
# get list/choices for inputs
|
19 |
+
CITIES = ['Accra', 'Aflao', 'Akim Oda', 'Akwatia', 'Bekwai', 'Cape coast', 'Elmina,', 'Gbawe', 'Ho', 'Hohoe', 'intampo', 'Koforidua', 'Kumasi', 'Mampong', 'Obuasi', 'Prestea', 'Suhum', 'Tamale', 'Techiman', 'Tema', 'Teshie', 'Winneba']
|
20 |
+
CLUSTER = [ i for i in range(0, 17)]
|
21 |
+
STORE_ID = [ i for i in range(1, 55)]
|
22 |
+
CATEGORY_ID = [ i for i in range(0, 35)]
|
23 |
+
|
24 |
+
|
25 |
# Setting the page configurations
|
26 |
st.set_page_config(page_title = "Prediction Forecasting", layout= "wide", initial_sidebar_state= "auto")
|
27 |
|
28 |
# Setting the page title
|
29 |
st.title("Grocery Store Forecasting Prediction")
|
30 |
|
|
|
|
|
|
|
31 |
|
32 |
+
# src\app\images1.jpg
|
33 |
image1 = Image.open('images1.jpg')
|
|
|
34 |
|
35 |
+
|
36 |
+
def make_prediction(store_id, category_id, onpromotion, city, store_type, cluster, date):
|
|
|
|
|
37 |
|
38 |
|
39 |
parameters = {
|
40 |
'store_id':int(store_id),
|
41 |
'category_id':int(category_id),
|
42 |
'onpromotion' :int(onpromotion),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
'city' : city,
|
44 |
'store_type' : int(store_type),
|
45 |
'cluster': int(cluster),
|
46 |
+
'date_': date,
|
47 |
|
48 |
}
|
49 |
|
50 |
+
# make a request to the api
|
51 |
response = requests.post(url=f'{URL}{API_ENDPOINT}', params=parameters)
|
52 |
+
|
53 |
sales_value = response.json()['sales']
|
54 |
+
|
55 |
sales_value = round(sales_value, 4)
|
56 |
return sales_value
|
57 |
|
|
|
60 |
|
61 |
st.sidebar.markdown('User Input Details and Information')
|
62 |
|
63 |
+
# Create interface
|
64 |
+
date= st.sidebar.date_input("Enter the Date",datetime.date(2023, 6, 30))
|
65 |
+
store_id= st.sidebar.selectbox('Store id', options=STORE_ID)
|
66 |
+
category_id= st.sidebar.selectbox('categegory_id', options=CATEGORY_ID)
|
67 |
+
onpromotion= st.sidebar.number_input('onpromotion', step=1)
|
68 |
+
city = st.sidebar.selectbox("city:", options= CITIES)
|
69 |
+
store_type= st.sidebar.selectbox('type', options=[0, 1, 2, 3, 4])
|
70 |
+
cluster = st.sidebar.selectbox('cluster', options = CLUSTER )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
# make prediction
|
73 |
+
sales_value = make_prediction(store_id, category_id, onpromotion,city, store_type, cluster, date)
|
|
|
|
|
|
|
74 |
|
75 |
# get predicted value
|
76 |
+
if st.sidebar.button('Predict', use_container_width=True, type='primary'):
|
77 |
st.success('The predicted target is ' + str(sales_value))
|
78 |
|
79 |
|