singhina commited on
Commit
4fe2e0f
·
1 Parent(s): ad3f3dd

Deploy Streamlit UI (connects to singhina/superkart-backend)

Browse files
Files changed (1) hide show
  1. 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
- BACKEND_URL = os.getenv(
9
- "BACKEND_URL",
10
- "https://singhina-superkart-backend.hf.space"
11
- )
12
 
13
- c1, c2 = st.columns(2)
14
- with c1:
15
- pw = st.number_input("Product Weight", 0.0,100.0,12.5,0.1)
16
- pa = st.number_input("Allocated Area Ratio", 0.0, 1.0,0.08,0.005)
17
- mrp = st.number_input("Product MRP ()", 0.0,1000.0,50.0,1.0)
18
- year= st.number_input("Store Established Year",1900,2025,2015,1)
19
- size= st.selectbox("Store Size", ["Low","Medium","High"])
20
- with c2:
21
- city = st.selectbox("City Tier", ["Tier 1","Tier 2","Tier 3"])
22
- stype= st.selectbox("Store Type", [
23
- "Departmental Store","Supermarket Type 1",
24
- "Supermarket Type 2","Food Mart"
25
- ])
26
- prefix=st.text_input("Product Prefix","FD")
27
- pnum =st.number_input("Product Numeric ID", 0,100000,6114,1)
28
- age =st.number_input("Store Age (yrs)", 0, 50, int(pd.Timestamp.now().year-year),1)
 
 
 
 
 
 
29
 
30
- if st.button(" Predict"):
31
- payload={"data":[{
 
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
- r = requests.post(f"{BACKEND_URL}/predict", json=payload)
44
- r.raise_for_status()
45
- pred = r.json()["predictions"][0]
46
- st.success(f" Forecasted Sales: ₹{pred:,.2f}")
 
 
 
 
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}")