Shaggys86 commited on
Commit
be4e938
·
verified ·
1 Parent(s): baa50bc

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -13
  2. app.py +61 -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,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import requests
4
+
5
+ # Streamlit UI for SuperKart Product store Revenue Prediction
6
+ st.title("SuperKart Product store Revenue Prediction App")
7
+ st.write("This app forecast the sales revenue of its outlets for various products.")
8
+ st.write("Fill in the required inputs below and get a prediction.")
9
+
10
+ Product_type_values = ["Frozen Foods", "Dairy", "Canned", "Baking Goods","Health and Hygiene", "Snack Foods", "Meat", "Household","Hard Drinks", "Fruits and Vegetables", "Breads", "Soft Drinks", "Breakfast", "Others", "Starchy Foods", "Seafood"]
11
+ sorted_options = sorted(Product_type_values)
12
+
13
+ # Collect user input
14
+ Product_Weight: st.number_input("Please enter the Product Weight", min_value=0.0, value=50.0)
15
+ Product_Sugar_Content: st.selectbox('Please select Product Sugar Content',["Low Sugar","No Sugar","Regular","reg"])
16
+ Product_Allocated_Area: st.number_input("Please enter the amount of area to be allocated for the product", min_value=0.0, value=500.0)
17
+ Product_Type: st.selectbox("Please select product Type",sorted_options)
18
+ Product_MRP: st.number_input("Please enter the Product MRP", min_value=0.0, value=500.0)
19
+ Store_Id: st.selectbox("Please select store",["OUT001","OUT002","OUT003","OUT004"], key="Store_Id", on_change = update_fields)
20
+ Store_Establishment_Year: st.text_input("Store Establishment Year (Autofilled)", st.session_state.Store_Establishment_Year_value, key="Store_Establishment_Year")
21
+ Store_Size: st.text_input("Store size (Autofilled)", st.session_state.Store_Size_value, key="Store_Size")
22
+ Store_Location_City_Type: st.text_input("Store location City type (Autofilled)", st.session_state.Store_Location_City_Type_value, key="Store_Location_City_Type")
23
+ Store_Type: st.text_input("Store Type (Autofilled)", st.session_state.Store_Type_value, key="Store_Type")
24
+
25
+
26
+ # Create input DataFrame
27
+ input_data = {
28
+ 'Product_Weight': Product_Weight,
29
+ 'Product_Sugar_Content': Product_Sugar_Content,
30
+ 'Product_Allocated_Area': Product_Allocated_Area,
31
+ 'Product_Type': Product_Type,
32
+ 'Product_MRP': Product_MRP,
33
+ 'Store_Id': Store_Id,
34
+ 'Store_Establishment_Year': Store_Establishment_Year,
35
+ 'Store_Size': Store_Size,
36
+ 'Store_Location_City_Type': Store_Location_City_Type,
37
+ 'Store_Type': Store_Type
38
+ }
39
+
40
+ if st.button("Predict", type='primary'):
41
+ response = requests.post("https://Shaggys86-SuperKartProductSalesPrediction.hf.space/v1/product", json=input_data) # enter user name and space name before running the cell
42
+ if response.status_code == 200:
43
+ result = response.json()
44
+ predicted_sales = result["Predicted_Product_store_Sales"]
45
+ st.success(f"The Predicted Product Store Sales Value: {predicted_sales}")
46
+ else:
47
+ st.error("Error in API request")
48
+
49
+ # Batch Prediction
50
+ st.subheader("Batch Prediction")
51
+
52
+ file = st.file_uploader("Upload CSV file", type=["csv"])
53
+ if file is not None:
54
+ if st.button("Predict for Batch", type='primary'):
55
+ response = requests.post("https://Shaggys86-SuperKartProductSalesPrediction.hf.space/v1/productbatch", files={"file": file}) # enter user name and space name before running the cell
56
+ if response.status_code == 200:
57
+ result = response.json()
58
+ st.header("Batch Prediction Results")
59
+ st.write(result)
60
+ else:
61
+ 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