File size: 2,836 Bytes
cff19c5
 
 
 
 
 
 
 
 
 
 
 
 
 
5282a1b
cff19c5
 
 
 
 
 
 
 
 
 
5282a1b
cff19c5
 
 
 
 
 
 
344052b
cff19c5
 
 
 
 
344052b
cff19c5
 
 
 
 
 
 
 
 
 
 
 
344052b
cff19c5
 
344052b
 
 
 
cff19c5
344052b
cff19c5
 
344052b
 
 
cff19c5
344052b
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
import streamlit as st
import requests
import pandas as pd

# Configure page
st.set_page_config(page_title="SuperKart Sales Estimator", layout="centered")
st.title("SuperKart Sales Forecast Tool")

# Input form
st.subheader("Provide Product & Store Information")

col_left, col_right = st.columns(2)

with col_left:
    #product_id = st.text_input("Product ID", value="P0001")
    weight = st.number_input("Product Weight (in kg)", min_value=0.0, step=0.1, value=1.0)
    sugar_level = st.selectbox("Sugar Content", ["Low", "Medium", "Regular", "reg"])
    allocated_area = st.number_input("Display Area (sq.m)", min_value=0.01, step=0.01, value=1.5)
    category = st.selectbox("Category", [
        "Baking Goods", "Canned", "Dairy", "Frozen Foods", "Health and Hygiene",
        "Household", "Meat", "Others", "Snack Foods", "Soft Drinks", "Starchy Foods"
    ])
    mrp = st.number_input("MRP ($)", min_value=1.0, max_value=1000.0, step=1.0, value=100.0)

with col_right:
    #store_id = st.text_input("Store ID", value="S0001")
    establishment_year = st.number_input("Year Store Opened", min_value=1990, max_value=2025, step=1, value=2010)
    store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
    city_tier = st.selectbox("Location Tier", ["Tier 1", "Tier 2", "Tier 3"])
    store_format = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Supermarket Type3", "Grocery Store"])

# Create JSON payload
payload = {
    #"Product_ID": product_id,
    "Product_Weight": weight,
    "Product_Sugar_Content": sugar_level,
    "Product_Allocated_Area": allocated_area,
    "Product_Type": category,
    "Product_MRP": mrp,
    #"Store_ID": store_id,
    "Store_Establishment_Year": establishment_year,
    "Store_Size": store_size,
    "Store_Location_City_Type": city_tier,
    "Store_Type": store_format
}

# Button to call API
if st.button("Get Sales Prediction"):
    with st.spinner("Processing your request..."):
        try:
            api_url = "https://mohith96-SuperKartBackend.hf.space/predict"
            response = requests.post(api_url, json=payload, timeout=10)

            if response.status_code == 200:
                result = response.json()
                predicted_value = result.get("Predicted_Sales") or result.get("Predicted_Sales_Product")

                if predicted_value is not None:
                    st.success(f"Predicted Sales: $ {predicted_value:.2f}")
                else:
                    st.warning(f"Unexpected response format: {result}")
            else:
                st.error(f"API returned {response.status_code}: {response.text}")

        except requests.exceptions.RequestException as req_err:
            st.error(f"API request failed: {req_err}")
        except Exception as error:
            st.error(f"Unexpected error: {error}")