Na-Rajan commited on
Commit
b753fd3
·
verified ·
1 Parent(s): 222f762

Add SuperKart Streamlit frontend deployment files

Browse files
Files changed (3) hide show
  1. Dockerfile +12 -0
  2. app.py +52 -0
  3. requirements.txt +2 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY . .
9
+
10
+ EXPOSE 8501
11
+
12
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Streamlit frontend that collects product/store details and calls the Flask backend API
3
+
4
+ import streamlit as st
5
+ import requests
6
+
7
+ # Backend URL: within the shared Docker network, containers reach each other
8
+ # by container name. Defaults to the container name used when running the
9
+ # backend container (see deployment instructions).
10
+ BACKEND_URL = os.environ.get("BACKEND_URL", "http://superkart-backend:7860")
11
+
12
+ st.set_page_config(page_title="SuperKart Sales Forecasting", layout="centered")
13
+ st.title("SuperKart Sales Forecasting")
14
+ st.write("Enter the product and store details below to forecast sales revenue.")
15
+
16
+ # ----- Input widgets -----
17
+ product_weight = st.number_input("Product Weight", min_value=0.0, value=12.66, step=0.1)
18
+ product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
19
+ product_allocated_area = st.number_input(
20
+ "Product Allocated Area", min_value=0.0, max_value=1.0, value=0.027, step=0.001, format="%.3f"
21
+ )
22
+ product_mrp = st.number_input("Product MRP", min_value=0.0, value=117.08, step=0.1)
23
+ store_size = st.selectbox("Store Size", ["High", "Medium", "Small"])
24
+ store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
25
+ store_type = st.selectbox(
26
+ "Store Type",
27
+ ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Supermarket Type3", "Food Mart"],
28
+ )
29
+ product_id_char = st.selectbox("Product Id Prefix", ["FD", "DR", "NC"])
30
+ store_age_years = st.number_input("Store Age (Years)", min_value=0, value=16, step=1)
31
+ product_type_category = st.selectbox("Product Type Category", ["Perishables", "Non Perishables"])
32
+
33
+ if st.button("Predict Sales"):
34
+ payload = {
35
+ "Product_Weight": product_weight,
36
+ "Product_Sugar_Content": product_sugar_content,
37
+ "Product_Allocated_Area": product_allocated_area,
38
+ "Product_MRP": product_mrp,
39
+ "Store_Size": store_size,
40
+ "Store_Location_City_Type": store_location_city_type,
41
+ "Store_Type": store_type,
42
+ "Product_Id_char": product_id_char,
43
+ "Store_Age_Years": store_age_years,
44
+ "Product_Type_Category": product_type_category,
45
+ }
46
+ try:
47
+ response = requests.post(f"{BACKEND_URL}/v1/predict", json=payload)
48
+ response.raise_for_status()
49
+ prediction = response.json()["predicted_Product_Store_Sales_Total"]
50
+ st.success(f"Predicted Sales: {prediction}")
51
+ except Exception as e:
52
+ st.error(f"Error while calling the backend API: {e}")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit==1.38.0
2
+ requests==2.32.4