vinodcwanted commited on
Commit
82ccd56
·
verified ·
1 Parent(s): 83065f2

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +88 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a minimal base image with Python 3.9 installed
2
+ FROM python:3.9-slim
3
+
4
+ # Set the working directory inside the container to /app
5
+ WORKDIR /app
6
+
7
+ # Copy all files from the current directory on the host to the container's /app directory
8
+ COPY . .
9
+
10
+ # Install Python dependencies listed in requirements.txt
11
+ RUN pip3 install -r requirements.txt
12
+
13
+ # Define the command to run the Streamlit app on port 8501 and make it accessible externally
14
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
15
+
16
+ # NOTE: Disable XSRF protection for easier external access in order to make batch predictions
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import pandas as pd
4
+
5
+ st.set_page_config(page_title="SuperKart Sales Prediction", page_icon="🛒", layout="centered")
6
+ st.title("🛒 SuperKart Sales Prediction")
7
+
8
+ # --- API base (set your HF Space URL here) ---
9
+ api_url = st.text_input(
10
+ "API Base URL",
11
+ value="https://vinodcwanted-SuperKart.hf.space",
12
+ help="Your Flask API base (no trailing slash). Example: https://thiresh-rentalpricepredictionbackend.hf.space",
13
+ )
14
+
15
+ st.markdown("### Product Details")
16
+ col1, col2 = st.columns(2)
17
+ with col1:
18
+ product_weight = st.number_input("Product_Weight", min_value=0.0, value=12.5, step=0.1)
19
+ product_alloc_area = st.number_input("Product_Allocated_Area", min_value=0.0, value=0.05, step=0.001, format="%.3f")
20
+ product_mrp = st.number_input("Product_MRP", min_value=0.0, value=150.0, step=0.1)
21
+ product_id = st.text_input("Product_Id (optional)", value="", help="If provided, API derives product_categories from its prefix (FD/NC/DR).")
22
+ with col2:
23
+ product_sugar_content = st.selectbox("Product_Sugar_Content", ["Low Sugar", "Regular", "No Sugar"])
24
+ product_type = st.selectbox(
25
+ "Product_Type",
26
+ [
27
+ "Frozen Foods","Dairy","Canned","Baking Goods","Health and Hygiene","Snack Foods","Meat",
28
+ "Household","Hard Drinks","Fruits and Vegetables","Breads","Soft Drinks","Breakfast",
29
+ "Others","Starchy Foods","Seafood"
30
+ ],
31
+ )
32
+ product_categories = st.selectbox(
33
+ "product_categories (optional)",
34
+ ["(leave blank)","FD","NC","DR"],
35
+ help="If left blank, API will derive from Product_Id (if provided)."
36
+ )
37
+
38
+ st.markdown("### Store Details")
39
+ col3, col4 = st.columns(2)
40
+ with col3:
41
+ store_size = st.selectbox("Store_Size", ["Small", "Medium", "High"])
42
+ store_type = st.selectbox("Store_Type", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"])
43
+ with col4:
44
+ store_city_type = st.selectbox("Store_Location_City_Type", ["Tier 1", "Tier 2", "Tier 3"])
45
+ store_est_year = st.number_input("Store_Establishment_Year", min_value=1900, max_value=2025, value=2005, step=1,
46
+ help="API will compute Establishment_age = 2025 - this year.")
47
+
48
+ # Build payload (single JSON)
49
+ payload = {
50
+ "Product_Weight": product_weight,
51
+ "Product_Sugar_Content": product_sugar_content,
52
+ "Product_Allocated_Area": product_alloc_area,
53
+ "Product_Type": product_type,
54
+ "Product_MRP": product_mrp,
55
+ "Store_Establishment_Year": int(store_est_year),
56
+ "Store_Size": store_size,
57
+ "Store_Location_City_Type": store_city_type,
58
+ "Store_Type": store_type,
59
+ }
60
+
61
+ # Optional fields
62
+ if product_id.strip():
63
+ payload["Product_Id"] = product_id.strip()
64
+ if product_categories != "(leave blank)":
65
+ payload["product_categories"] = product_categories
66
+
67
+ st.markdown("---")
68
+ if st.button("Predict"):
69
+ if not api_url.strip():
70
+ st.error("Please enter your API Base URL.")
71
+ else:
72
+ try:
73
+ endpoint = api_url.rstrip("/") + "/v1/sale"
74
+ with st.spinner("Contacting API..."):
75
+ resp = requests.post(endpoint, json=payload, timeout=30)
76
+ if resp.status_code == 200:
77
+ data = resp.json()
78
+ if "prediction" in data:
79
+ st.success(f"Predicted Sales: **{data['prediction']}**")
80
+ else:
81
+ st.warning(f"API responded without 'prediction' key:\n{data}")
82
+ else:
83
+ st.error(f"API error {resp.status_code}: {resp.text}")
84
+ except Exception as e:
85
+ st.error(f"Request failed: {e}")
86
+
87
+ with st.expander("Show request payload"):
88
+ st.json(payload)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas==2.2.2
2
+ requests==2.32.3
3
+ streamlit==1.43.2