File size: 3,792 Bytes
1a94601
 
 
592be4c
5f3ee9a
592be4c
1a94601
 
 
 
 
 
 
 
a531007
 
 
 
 
1a94601
a531007
1a94601
 
 
 
 
 
9f732f6
 
 
 
 
bc4a0f1
9f732f6
 
 
 
 
1a94601
b016999
 
 
 
 
 
 
 
 
 
 
 
1a94601
 
6dfe4de
1a94601
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6dfe4de
1a94601
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import requests
from transformers import pipeline
import joblib

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

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

# Collect business input for features
Product_Weight = st.number_input("Product Weight", min_value=0.0, value=12.66)
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Sugar_Low Sugar", "Sugar_Regular", "Sugar_No Sugar", "Sugar_regular"])
Product_Allocated_Area = st.selectbox("Product Allocated Area", ["Area_Small", "Area_Medium", "Area_Large"])
Product_MRP = st.selectbox("Product MRP", ["Size_Low", "Size_Medium", "Size_High"])
Store_Size = st.selectbox("Store Size", ["Size_Small", "Size_Medium", "Size_Large"])
Store_Age = st.number_input("Store Age", min_value=1987, max_value=2009)
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
Store_Type = st.selectbox("Store Type", ["Type_Supermarket Type1", "Type_Supermarket Type2", "Type_Departmental Store", "Type_Grocery Store"])
Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1987, max_value=2009)
Product_Type = st.selectbox("Product Type", ["Baking Goods", "Frozen Foods", "Dairy", "Canned", "Health and Hygiene", "Snack Foods", "Meat", "Household", "Hard Drinks",
                                             "Fruits and Vegetables", "Breads", "Soft Drinks", "Breakfast", "Others", "Starchy Foods", "Seafood"])

# Convert user input into a DataFrame
input_data = pd.DataFrame({
    "Product_Weight": Product_Weight,
    "Product_Sugar_Content": Product_Sugar_Content,
    "Product_Allocated_Area": Product_Allocated_Area,
    "Product_MRP": Product_MRP,
    "Store_Size": Store_Size,
    "Store_Age": Store_Age,
    "Store_Location_City_Type": Store_Location_City_Type,
    "Store_Type": Store_Type,
    "Store_Establishment_Year": Store_Establishment_Year,
    "Product_Type": Product_Type
}, index=[0])

def predict_sales(input_data):
    backend_url = "https://MBG0903-SuperKartSalesPredictionBackend.hf.space/v1/predict"  # THIS LINE IS CRUCIAL
    headers = {'Content-Type': 'application/json'}
    try:
        response = requests.post(backend_url, json=input_data, headers=headers)
        response.raise_for_status()  # Raise an exception for bad status codes
        prediction = response.json()['Predicted sales']
        return prediction
    except requests.exceptions.RequestException as e:
        st.error(f"Error communicating with backend: {e}")
        return None

# Make prediction when the "Predict" button is clicked
if st.button("Predict"):
    response = requests.post("https://MBG0903-SuperKartSalesPredictionBackend.hf.space/v1/predict", json=input_data.to_dict(orient="records")[0])
    if response.status_code == 200:
        prediction = response.json()['Predicted Sales (in dollars)']
        st.success(f"Predicted Sales (in dollars): {prediction}")
    else:
        st.error("Error making prediction.")

# 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"):
        response = requests.post("https://MBG0903-SuperKartSalesPredictionBackend.hf.space/v1/predict/batch", 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.")