File size: 1,674 Bytes
3353e64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests

st.title("🛒 SuperKart Sales Predictor")

# Sidebar inputs
Product_Weight = st.sidebar.number_input("Product Weight", min_value=0.0, max_value=100.0, value=10.0)
Product_Sugar_Content = st.sidebar.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
Product_Allocated_Area = st.sidebar.number_input("Allocated Area", min_value=0.0, max_value=10.0, value=0.5)
Product_Type = st.sidebar.text_input("Product Type", "Snack foods")
Product_MRP = st.sidebar.number_input("MRP", min_value=0.0, max_value=1000.0, value=100.0)
Store_Size = st.sidebar.selectbox("Store Size", ["Small", "Medium", "High"])
Store_Location_City_Type = st.sidebar.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])
Store_Type = st.sidebar.text_input("Store Type", "Supermarket Type1")

if st.button("Predict Sales"):
    sample = [{
        "Product_Weight": Product_Weight,
        "Product_Sugar_Content": Product_Sugar_Content,
        "Product_Allocated_Area": Product_Allocated_Area,
        "Product_Type": Product_Type,
        "Product_MRP": Product_MRP,
        "Store_Size": Store_Size,
        "Store_Location_City_Type": Store_Location_City_Type,
        "Store_Type": Store_Type
    }]

    url = "https://akhilraja-superkart-flask-api.hf.space/predict"
    try:
        response = requests.post(url, json=sample)
        response.raise_for_status()
        prediction = response.json().get("predictions", [None])[0]
        if prediction is not None:
            st.success(f"Predicted Sales: {prediction:.2f}")
        else:
            st.error("No prediction returned.")
    except Exception as e:
        st.error(f"Error: {e}")