AdarshRL commited on
Commit
172980d
·
verified ·
1 Parent(s): ec29842

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -13
  2. app.py +81 -0
  3. requirements.txt +3 -3
Dockerfile CHANGED
@@ -1,20 +1,16 @@
1
- FROM python:3.13.5-slim
 
2
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- git \
9
- && rm -rf /var/lib/apt/lists/*
10
-
11
- COPY requirements.txt ./
12
- COPY src/ ./src/
13
 
 
14
  RUN pip3 install -r requirements.txt
15
 
16
- EXPOSE 8501
17
-
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
19
 
20
- 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
 
16
+ # NOTE: Disable XSRF protection for easier external access in order to make batch predictions
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import streamlit as st
3
+ import pandas as pd
4
+
5
+ st.title("SuperKart Sales Prediction")
6
+
7
+ # Batch Prediction
8
+ st.subheader("Online Prediction")
9
+
10
+ # Input fields for product data
11
+ Product_Id = st.text_input("Product_Id")
12
+ Product_Weight = st.number_input("Product_Weight (Product's weight in KG)", min_value=0, max_value=900, value=2)
13
+ Product_Sugar_Content = st.selectbox("Product_Sugar_Content (Product's sugar content)", ["No Sugar", "Low Sugar", "Regular"])
14
+ Product_Allocated_Area = st.number_input("Product_Allocated_Area (Fraction of total store area allocated to this product)", min_value=0, max_value=1, value=0.29)
15
+
16
+ product_type_values = [
17
+ 'Meat',
18
+ 'Snack Foods',
19
+ 'Hard Drinks',
20
+ 'Dairy',
21
+ 'Canned',
22
+ 'Soft Drinks',
23
+ 'Health and Hygiene',
24
+ 'Baking Goods',
25
+ 'Bread',
26
+ 'Breakfast',
27
+ 'Frozen Foods',
28
+ 'Fruits and Vegetables',
29
+ 'Household',
30
+ 'Seafood',
31
+ 'Starchy Foods',
32
+ 'Others'
33
+ ]
34
+ Product_Type = st.selectbox("Product_Type (Type of the product)", product_type_values)
35
+
36
+ Product_MRP = st.number_input("Product_MRP (Max Retail Price of the product in dollars)", min_value=0.0, value=119.0)
37
+ Store_Size = st.selectbox("Store_Size (Size category of the store)", ["Small","Medium","High"])
38
+ Store_Location_City_Type = st.selectbox("Store_Location_City_Type(Type of city in which store is located)", ["Tier 3", "Tier 2", "Tier 1"])
39
+
40
+ store_type_values = [
41
+ 'Departmental Store',
42
+ 'Supermarket Type 1',
43
+ 'Supermarket Type 2',
44
+ 'Food Mart'
45
+ ]
46
+ Store_Type = st.selectbox("Store_Type (Type of store depending on the products that are being sold there)", store_type_values)
47
+
48
+ product_data = {
49
+ 'Product_Id': Product_Id,
50
+ 'Product_Weight': Product_Weight,
51
+ 'Product_Sugar_Content': Product_Sugar_Content,
52
+ 'Product_Allocated_Area': Product_Allocated_Area,
53
+ 'Product_Type': Product_Type,
54
+ 'Product_MRP': Product_MRP,
55
+ 'Store_Size': Store_Size,
56
+ 'Store_Location_City_Type': Store_Location_City_Type,
57
+ 'Store_Type': Store_Type
58
+ }
59
+
60
+ if st.button("Predict", type='primary'):
61
+ response = requests.post("https://AdarshRL-SalesPredictionBackend.hf.space/v1/product", json=product_data) # enter user name and space name before running the cell
62
+ if response.status_code == 200:
63
+ result = response.json()
64
+ prediction = result["Prediction"]["Sales"] # Extract only the value
65
+ st.write(f"Based on the information provided, the product with ID {Product_Id} is likely to generate sales of: {prediction}.")
66
+ else:
67
+ st.error("Error in API request")
68
+
69
+ # Batch Prediction
70
+ st.subheader("Batch Prediction")
71
+
72
+ file = st.file_uploader("Upload CSV file", type=["csv"])
73
+ if file is not None:
74
+ if st.button("Predict for Batch", type='primary'):
75
+ response = requests.post("https://AdarshRL-SalesPredictionBackend.hf.space/v1/productbatch", files={"file": file}) # enter user name and space name before running the cell
76
+ if response.status_code == 200:
77
+ result = response.json()
78
+ st.header("Batch Prediction Results")
79
+ st.write(result)
80
+ else:
81
+ st.error("Error in API request")
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- altair
2
- pandas
3
- streamlit
 
1
+ pandas==2.2.2
2
+ requests==2.28.1
3
+ streamlit==1.43.2