vinodcwanted commited on
Commit
726a255
·
verified ·
1 Parent(s): bb2de41

Upload folder using huggingface_hub

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