singhina commited on
Commit
d795107
ยท
1 Parent(s): 94edc3d

๐Ÿ”ฅ Full overwrite: deploy SuperKart UI

Browse files
Dockerfile DELETED
@@ -1,21 +0,0 @@
1
- FROM python:3.9-slim
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- software-properties-common \
9
- git \
10
- && rm -rf /var/lib/apt/lists/*
11
-
12
- COPY requirements.txt ./
13
- COPY src/ ./src/
14
-
15
- RUN pip3 install -r requirements.txt
16
-
17
- EXPOSE 8501
18
-
19
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
20
-
21
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md DELETED
@@ -1,19 +0,0 @@
1
- ---
2
- title: SuperKartUI
3
- emoji: ๐Ÿš€
4
- colorFrom: red
5
- colorTo: red
6
- sdk: docker
7
- app_port: 8501
8
- tags:
9
- - streamlit
10
- pinned: false
11
- short_description: Streamlit template space
12
- ---
13
-
14
- # Welcome to Streamlit!
15
-
16
- Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
17
-
18
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
19
- forums](https://discuss.streamlit.io).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py DELETED
@@ -1,31 +0,0 @@
1
- from flask import Flask, request, jsonify
2
- import pandas as pd
3
- import joblib
4
-
5
- app = Flask(__name__)
6
-
7
- MODEL_PATH = "best_sales_forecast_model.pkl"
8
- model = joblib.load(MODEL_PATH)
9
-
10
- FEATURE_COLUMNS = [
11
- "Product_Weight","Product_Allocated_Area","Product_MRP",
12
- "Store_Establishment_Year","Store_Size","Store_Location_City_Type",
13
- "Store_Type","Product_Prefix","Product_Num","Store_Age"
14
- ]
15
-
16
- @app.route("/")
17
- def home():
18
- return "SuperKart Sales Forecast API is up."
19
-
20
- @app.route("/predict", methods=["POST"])
21
- def predict():
22
- payload = request.get_json(force=True)
23
- df = pd.DataFrame(payload["data"])
24
- X = df[FEATURE_COLUMNS]
25
- preds = model.predict(X)
26
- return jsonify({"predictions": preds.tolist()})
27
-
28
- if __name__ == "__main__":
29
- import os
30
- port = int(os.environ.get("PORT", 5000))
31
- app.run(host="0.0.0.0", port=port)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
best_sales_forecast_model.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:6f13226779001590e025ef62b31e40021305709d38a5ab555e18bc1611208c97
3
- size 49997859
 
 
 
 
final_random_forest_model.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:7bbd80f25f24f85f9461b8ed48e52593e1916c60d892034781d145819376e721
3
- size 49995363
 
 
 
 
src/streamlit_app.py DELETED
@@ -1,40 +0,0 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
- import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
streamlit_app.py CHANGED
@@ -3,51 +3,51 @@ 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}")
 
3
  import requests
4
  import os
5
 
 
6
  st.set_page_config(page_title="SuperKart Forecast", layout="centered")
7
  st.title("๐Ÿ›’ SuperKart Quarterly Sales Forecast")
8
+ st.write("Enter details below, then click ๐Ÿ”ฎ Predict.")
9
 
 
10
  BACKEND_URL = os.getenv("BACKEND_URL", "$BACKEND_URL")
11
 
 
12
  with st.form("forecast_form"):
13
  c1, c2 = st.columns(2)
14
  with c1:
15
+ pw = st.number_input("Product Weight (kg)", 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(
29
+ "Store Age (yrs)",0,50,
30
+ int(pd.Timestamp.now().year - year),1
31
+ )
32
+ submit = st.form_submit_button("๐Ÿ”ฎ Predict")
33
 
34
+ if submit:
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
+ r = requests.post(f"{BACKEND_URL}/predict", json=payload, timeout=10)
49
+ r.raise_for_status()
50
+ pred = r.json()["predictions"][0]
51
+ st.success(f"๐Ÿš€ Forecasted Sales: โ‚น{pred:,.2f}")
52
  except Exception as e:
53
+ st.error(f"โŒ Prediction error: {e}")