AlbertoNuin commited on
Commit
5000ded
·
verified ·
1 Parent(s): 2db5391

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -13
  2. app.py +57 -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,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import requests
4
+
5
+ st.title("Super Kart Sales Predictor")
6
+
7
+ # Input fields for product and store data
8
+ Product_Weight = st.slider("Product Weight", min_value=0.0, value=12.0, max_value = 22.0)
9
+ Product_MRP = st.slider("Product MRP", min_value=30.0, value=145.0, max_value=260.0)
10
+ Product_Allocated_Area = st.slider("Product Allocated Area", min_value=0.0, value=0.05, max_value=0.3)
11
+ Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
12
+ Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
13
+ Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
14
+ Store_Type = st.selectbox("Store Type", ["Departmental Store ", "Supermarket Type1", "Supermarket Type2", "Food Mart"])
15
+ Store_Age_Years = st.slider("Store Age (Years)", min_value=0, value=15, max_value=40)
16
+ Product_Id_prefix = st.selectbox("Product ID Prefix", ["FD", "DR", "NC"])
17
+ Product_FD_perishable = st.selectbox("Product FD Perishable flag", ["Perishables", "Non Perishables"])
18
+
19
+ product_data = {
20
+ "Product_Weight": Product_Weight,
21
+ "Product_MRP": Product_MRP,
22
+ "Product_Allocated_Area": Product_Allocated_Area,
23
+ "Product_Sugar_Content": Product_Sugar_Content,
24
+ "Store_Size": Store_Size,
25
+ "Store_Location_City_Type": Store_Location_City_Type,
26
+ "Store_Type": Store_Type,
27
+ "Store_Age_Years": Store_Age_Years,
28
+ "Product_Id_prefix": Product_Id_prefix,
29
+ "Product_FD_perishable": Product_FD_perishable,
30
+ }
31
+
32
+ # Make prediction when the "Predict" button is clicked
33
+ if st.button("Predict", type='primary'):
34
+ response = requests.post("https://AlbertoNuin-SuperKartBackend.hf.space/v1/predict", json=product_data)
35
+ if response.status_code == 200:
36
+ result = response.json()
37
+ predicted_sales = result["Sales"]
38
+ st.write(f"Predicted Product Store Sales Total: {predicted_sales:.2f}")
39
+ else:
40
+ st.error("Error in API request")
41
+
42
+ # Section for batch prediction
43
+ st.subheader("Batch Prediction")
44
+
45
+ # Allow users to upload a CSV file for batch prediction
46
+ uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
47
+
48
+ # Make batch prediction when the "Predict Batch" button is clicked
49
+ if uploaded_file is not None:
50
+ if st.button("Predict Batch"):
51
+ response = requests.post("https://AlbertoNuin-SuperKartBackend.hf.space/v1/batch", files={"file": uploaded_file}) # Send file to Flask API
52
+ if response.status_code == 200:
53
+ predictions = response.json()
54
+ st.success("Batch predictions completed!")
55
+ st.write(predictions) # Display the predictions
56
+ else:
57
+ st.error("Error making batch prediction.")
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