File size: 3,275 Bytes
7b14dd8
 
 
 
 
 
 
 
 
 
 
 
 
6405a73
 
 
 
29a4399
6405a73
29a4399
 
6405a73
7b14dd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114efa4
7b14dd8
ec8b797
 
fdc590d
7b14dd8
 
3519d4b
7b14dd8
 
 
 
 
 
 
 
 
86e35aa
d0ce435
17f1b16
114efa4
7b14dd8
 
 
 
 
 
bb0384b
86e35aa
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
import streamlit as st
import pandas as pd
import requests

# Set the title of the Streamlit app
st.title("SuperKart Product sales Prediction")

# Section for online prediction
st.subheader("Online Prediction")

# Collect user input for product details
product_type = st.selectbox("Product Type",["Frozen Foods","Dairy","Canned","Baking Goods","Snack Foods","Meat","Fruits and Vegetables","Breads","Breakfast","Starchy Foods","Seafood"])
product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar","Regular","No Sugar"])

# Min, Max value taken from the statistics details captured in the EDA
# Mean value is taken as the default value
# Step is defined based on the range of numbers
# Keeping all the arguments in same type as expected by streamlit
product_mrp = st.number_input("MRP (in $)", min_value=31.0, max_value=267.0, step=1.0, value=147.0)
product_weight = st.number_input("Product Weight (in Ounce)", min_value=4.0, max_value=22.0, step=0.2, value=12.0)
product_allocated_area=st.number_input("Product Allocated area in %", min_value=0.4, max_value=30.0, step=0.1, value=0.7)

store_size = st.selectbox("Store Size", ["Small","Medium","High"])
store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1","Tier 2","Tier 3"])
store_type=st.selectbox("Store Type", ["Food Mart","Supermarket Type1","Supermarket Type2","Departmental Store"])

# Convert user input into a DataFrame
input_data = pd.DataFrame([{
   'Product_MRP': product_mrp,
    'Product_Type': product_type,
    'Product_Sugar_Content': product_sugar_content,
    'Product_Weight': product_weight,
    'Product_Allocated_Area': product_allocated_area/100,
    'Store_Size': store_size,
    'Store_Location_City_Type': store_location_city_type,
    'Store_Type': store_type
}])

# Make prediction when the "Predict" button is clicked
if st.button("Predict"):
    response = requests.post("https://deepacsr-ProductPricePredictionBackend.hf.space/v1/ProductSale", json=input_data.to_dict(orient='records')[0])  # Send data to Flask API
    if response.status_code == 200:
        prediction = response.json()
        st.success("Product sales predictions completed!")
        st.success(f"Predicted Sales Price (in dollars): {prediction}")
    else:
        st.error("Error making prediction.")
        st.error(f"Error code: {response.status_code}")

# Section for batch prediction
st.subheader("Batch Prediction")

# Allow users to upload a CSV file for batch prediction
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])

# Make batch prediction when the "Predict Batch" button is clicked
if uploaded_file is not None:
  if st.button("Predict Batch"):
        st.write(uploaded_file.name)
        st.write(uploaded_file.getvalue())
        response = requests.post("https://deepacsr-ProductPricePredictionBackend.hf.space//v1/batchsales",files={"file": uploaded_file})
        if response.status_code == 200:
            predictions = response.json()
            st.success("Batch predictions completed!")
            st.write(predictions)  # Display the predictions
        else:
            st.error("Error making batch prediction.")
            st.error(f"Error code: {response.status_code}")
            st.error(response.text)