File size: 2,444 Bytes
2a3cd6e
 
20561ea
 
 
 
 
2a3cd6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests
import os

# Ensure Streamlit writes config to a safe location
os.environ["STREAMLIT_HOME"] = "./.streamlit"
os.makedirs(os.environ["STREAMLIT_HOME"], exist_ok=True)
st.set_page_config(page_title="SuperKart Sales Predictor", page_icon="πŸ›’")
st.title("πŸ›’ SuperKart Sales Prediction")
st.markdown("Enter product and store details below to get the predicted sales.")

with st.form("prediction_form"):
    Product_Weight = st.number_input("Product Weight", value=12.0)
    Product_Sugar_Content = st.selectbox("Sugar Content", [0, 1])
    Product_Allocated_Area = st.number_input("Allocated Area", value=0.05)
    Product_MRP = st.number_input("Product MRP", value=150.0)
    Store_Size = st.selectbox("Store Size", [0, 1, 2])
    Store_Location_City_Type = st.selectbox("City Type", [0, 1, 2])
    Store_Type = st.selectbox("Store Type", [0, 1, 2, 3])
    Store_Age = st.slider("Store Age (years)", 0, 50, 10)

    product_types = [
        "Product_Type_Breads", "Product_Type_Breakfast", "Product_Type_Canned",
        "Product_Type_Dairy", "Product_Type_Frozen_Foods", "Product_Type_Fruits_and_Vegetables",
        "Product_Type_Hard_Drinks", "Product_Type_Health_and_Hygiene", "Product_Type_Household",
        "Product_Type_Meat", "Product_Type_Others", "Product_Type_Seafood",
        "Product_Type_Snack_Foods", "Product_Type_Soft_Drinks", "Product_Type_Starchy_Foods"
    ]
    selected_type = st.selectbox("Product Type", product_types)

    submitted = st.form_submit_button("Predict Sales")

if submitted:
    input_data = {
        "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_Location_City_Type": Store_Location_City_Type,
        "Store_Type": Store_Type,
        "Store_Age": Store_Age
    }

    for pt in product_types:
        input_data[pt] = 1 if pt == selected_type else 0

    api_url = "https://lokiiparihar-SuperkartBackendModalDeploy-XGBoost.hf.space/predict"  # Replace with actual backend

    try:
        with st.spinner("Predicting..."):
            res = requests.post(api_url, json=input_data)
            res.raise_for_status()
            st.success(f"βœ… Predicted Sales: {res.json()['prediction']:.2f} units")
    except Exception as e:
        st.error(f"Prediction failed: {e}")