Spaces:
Configuration error
Configuration error
Deploy Streamlit UI (connects to singhina/superkart-backend)
Browse files- streamlit_app.py +35 -26
streamlit_app.py
CHANGED
|
@@ -2,33 +2,39 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import requests, os
|
| 4 |
|
|
|
|
| 5 |
st.set_page_config(page_title="SuperKart Forecast", layout="centered")
|
| 6 |
st.title("🛒 SuperKart Quarterly Sales Forecast")
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
"https://singhina-superkart-backend.hf.space"
|
| 11 |
-
)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
with
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
"
|
| 24 |
-
"
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
"Product_Weight":pw,
|
| 33 |
"Product_Allocated_Area":pa,
|
| 34 |
"Product_MRP":mrp,
|
|
@@ -40,7 +46,10 @@ if st.button(" Predict"):
|
|
| 40 |
"Product_Num":pnum,
|
| 41 |
"Store_Age":age
|
| 42 |
}]}
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import requests, os
|
| 4 |
|
| 5 |
+
# Page config
|
| 6 |
st.set_page_config(page_title="SuperKart Forecast", layout="centered")
|
| 7 |
st.title("🛒 SuperKart Quarterly Sales Forecast")
|
| 8 |
|
| 9 |
+
# Point to your Flask backend
|
| 10 |
+
BACKEND_URL = os.getenv("BACKEND_URL", "$BACKEND_URL")
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# Input form
|
| 13 |
+
with st.form("forecast_form"):
|
| 14 |
+
c1, c2 = st.columns(2)
|
| 15 |
+
with c1:
|
| 16 |
+
pw = st.number_input("Product Weight (kg)", 0.0, 100.0, 12.5, 0.1)
|
| 17 |
+
pa = st.number_input("Allocated Area Ratio", 0.0, 1.0, 0.08, 0.005)
|
| 18 |
+
mrp = st.number_input("Product MRP (₹)", 0.0, 1000.0,50.0, 1.0)
|
| 19 |
+
year = st.number_input("Store Established Year",1900,2025,2015,1)
|
| 20 |
+
size = st.selectbox("Store Size", ["low","medium","high"])
|
| 21 |
+
with c2:
|
| 22 |
+
city = st.selectbox("City Tier", ["Tier 1","Tier 2","Tier 3"])
|
| 23 |
+
stype = st.selectbox("Store Type", [
|
| 24 |
+
"Departmental Store","Supermarket Type 1",
|
| 25 |
+
"Supermarket Type 2","Food Mart"
|
| 26 |
+
])
|
| 27 |
+
prefix = st.text_input("Product Prefix","FD")
|
| 28 |
+
pnum = st.number_input("Product Numeric ID", 0, 100000, 6114, 1)
|
| 29 |
+
age = st.number_input(
|
| 30 |
+
"Store Age (yrs)", 0, 50,
|
| 31 |
+
int(pd.Timestamp.now().year - year), 1
|
| 32 |
+
)
|
| 33 |
+
submitted = st.form_submit_button("🔮 Predict")
|
| 34 |
|
| 35 |
+
# Submit & show result
|
| 36 |
+
if submitted:
|
| 37 |
+
payload = {"data":[{
|
| 38 |
"Product_Weight":pw,
|
| 39 |
"Product_Allocated_Area":pa,
|
| 40 |
"Product_MRP":mrp,
|
|
|
|
| 46 |
"Product_Num":pnum,
|
| 47 |
"Store_Age":age
|
| 48 |
}]}
|
| 49 |
+
try:
|
| 50 |
+
r = requests.post(f"{BACKEND_URL}/predict", json=payload, timeout=10)
|
| 51 |
+
r.raise_for_status()
|
| 52 |
+
pred = r.json()["predictions"][0]
|
| 53 |
+
st.success(f"🚀 Forecasted Sales: ₹{pred:,.2f}")
|
| 54 |
+
except Exception as e:
|
| 55 |
+
st.error(f"❌ Error: {e}")
|