Spaces:
Configuration error
Configuration error
๐ฅ Deploy SuperKart Streamlit UI
Browse files- streamlit_app.py +53 -0
streamlit_app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Page config
|
| 7 |
+
st.set_page_config(page_title="SuperKart Forecast", layout="centered")
|
| 8 |
+
st.title("๐ SuperKart Quarterly Sales Forecast")
|
| 9 |
+
st.write("Fill in the product and store details below, then click ๐ฎ Predict.")
|
| 10 |
+
|
| 11 |
+
# Backend URL
|
| 12 |
+
BACKEND_URL = os.getenv("BACKEND_URL", "$BACKEND_URL")
|
| 13 |
+
|
| 14 |
+
# Input form
|
| 15 |
+
with st.form("forecast_form"):
|
| 16 |
+
c1, c2 = st.columns(2)
|
| 17 |
+
with c1:
|
| 18 |
+
pw = st.number_input("Product Weight (kg)", 0.0, 100.0, 12.5, 0.1)
|
| 19 |
+
pa = st.number_input("Allocated Area Ratio", 0.0, 1.0, 0.08, 0.005)
|
| 20 |
+
mrp = st.number_input("Product MRP (โน)", 0.0, 1000.0, 50.0, 1.0)
|
| 21 |
+
year = st.number_input("Store Established Year", 1900, 2025, 2015, 1)
|
| 22 |
+
size = st.selectbox("Store Size", ["low", "medium", "high"])
|
| 23 |
+
with c2:
|
| 24 |
+
city = st.selectbox("City Tier", ["Tier 1", "Tier 2", "Tier 3"])
|
| 25 |
+
stype = st.selectbox("Store Type", [
|
| 26 |
+
"Departmental Store", "Supermarket Type 1",
|
| 27 |
+
"Supermarket Type 2", "Food Mart"
|
| 28 |
+
])
|
| 29 |
+
prefix = st.text_input("Product Prefix", "FD")
|
| 30 |
+
pnum = st.number_input("Product Numeric ID", 0, 100000, 6114, 1)
|
| 31 |
+
age = st.number_input("Store Age (yrs)", 0, 50, int(pd.Timestamp.now().year - year), 1)
|
| 32 |
+
submitted = st.form_submit_button("๐ฎ Predict")
|
| 33 |
+
|
| 34 |
+
if submitted:
|
| 35 |
+
payload = {"data": [{
|
| 36 |
+
"Product_Weight": pw,
|
| 37 |
+
"Product_Allocated_Area": pa,
|
| 38 |
+
"Product_MRP": mrp,
|
| 39 |
+
"Store_Establishment_Year": year,
|
| 40 |
+
"Store_Size": size,
|
| 41 |
+
"Store_Location_City_Type": city,
|
| 42 |
+
"Store_Type": stype,
|
| 43 |
+
"Product_Prefix": prefix,
|
| 44 |
+
"Product_Num": pnum,
|
| 45 |
+
"Store_Age": age
|
| 46 |
+
}]}
|
| 47 |
+
try:
|
| 48 |
+
resp = requests.post(f"{BACKEND_URL}/predict", json=payload, timeout=10)
|
| 49 |
+
resp.raise_for_status()
|
| 50 |
+
pred = resp.json()["predictions"][0]
|
| 51 |
+
st.success(f"๐ Forecasted Sales: โน{pred:,.2f}")
|
| 52 |
+
except Exception as e:
|
| 53 |
+
st.error(f"โ Prediction error: {e}")
|