File size: 2,160 Bytes
7cec589
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0dcd302
7cec589
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests

# Streamlit UI for Sales Prediction
st.set_page_config(page_title="SuperKart Sales Prediction", page_icon="๐Ÿ›’")
st.title("๐Ÿ›’ SuperKart Sales Prediction App")
st.write("This tool predicts SuperKart Sales. Enter the required information below.")


# Model Choice
model_choice = st.selectbox(
    "Select Model",
    options=["dt", "xgb"],
    format_func=lambda x: "Decision Tree" if x == "dt" else "XGBoost"
)

# Collect user input based on dataset columns
product_weight = st.number_input("Product Weight", min_value=0.0, value=10.0)
sugar = st.selectbox("Sugar Content Code", [0, 1, 2])
area = st.number_input("Allocated Area", min_value=0.0, value=0.05)
product_type = st.number_input("Product Type Code", min_value=0, value=1)
mrp = st.number_input("Product MRP", min_value=0.0, value=100.0)
store_size = st.selectbox("Store Size Code", [0, 1, 2])
city = st.selectbox("City Type Code", [0, 1, 2])
store_type = st.number_input("Store Type Code", min_value=0, value=1)
store_age = st.number_input("Store Age", min_value=0, value=10)

# Payload to send to Flask API
sample = {
    "model": model_choice,
    "Product_Weight": product_weight,
    "Product_Sugar_Content": sugar,
    "Product_Allocated_Area": area,
    "Product_Type": product_type,
    "Product_MRP": mrp,
    "Store_Size": store_size,
    "Store_Location_City_Type": city,
    "Store_Type": store_type,
    "Store_Age": store_age
}

# API URL (Hugging Face backend)
API_URL = "https://Lokiiparihar-SuperKart_API.hf.space/predict"

if st.button("Predict", type="primary"):
    with st.spinner("๐Ÿ”ฎ Predicting sales..."):
        try:
            response = requests.post(API_URL, json=sample, timeout=20)

            if response.status_code == 200:
                result = response.json()
                sales_prediction = result["Prediction"]
                st.success(f"๐Ÿ’ฐ Predicted Sales: {sales_prediction:.2f}")

            else:
                st.error(f"โŒ API Error {response.status_code}")
                st.code(response.text)

        except Exception as e:
            st.error("โŒ Request failed")
            st.code(str(e))