danycontre commited on
Commit
8a9d207
·
verified ·
1 Parent(s): 336a8f9

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -13
  2. app.py +58 -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,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import requests
4
+
5
+ # Streamlit UI for Customer Churn Prediction
6
+ st.title("Product sales prediction")
7
+ st.write("This tool predicts product sales on their details. Enter the required information below.")
8
+
9
+ # Collect user input based on dataset columns
10
+ Product_Id = st.string('Product ID')
11
+ Product_Weight = st.number_input('Product Weight'),
12
+ Product_Sugar_Content = st.selectbox('Product Sugar Content', ['No Sugar', 'Low Sugar', 'Regular'])
13
+ Product_Allocated_Area = st.number_input('Product Allocated Area'),
14
+ Product_Type = st.selectbox('Product Type', ['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']),
15
+ Product_MRP = st.number_input('Product MRP'),
16
+ Store_Id = st.string('Store ID')
17
+ Store_Size = st.selectbox('Store Size', ['Medium', 'High', 'Small']),
18
+ Store_Establishment_Year = st.number_input('Store Establishment Year'),
19
+ Store_Location_City_Type = st.selectbox('Store Location City Type', ['Tier 1', 'Tier 2', 'Tier 3'])
20
+ Store_Type = st.selectbox('Store Type', ['Supermarket Type2', 'Departmental Store', 'Supermarket Type1','Food Mart'])
21
+
22
+ # Convert categorical inputs to match model training
23
+ customer_data = {
24
+ 'Product_Weight':Product_Weight,
25
+ 'Product_Sugar_Content': Product_Sugar_Content,
26
+ 'Product_Allocated_Area': Product_Allocated_Area,
27
+ 'Product_Type': Product_Type,
28
+ 'Product_MRP': Product_MRP,
29
+ 'Store_Id': Store_Id,
30
+ 'Store_Size': Store_Size,
31
+ 'Store_Establishment_Year': Store_Establishment_Year,
32
+ 'Store_Location_City_Type': Store_Location_City_Type
33
+ 'Store_Type': Store_Type
34
+ }
35
+
36
+
37
+ if st.button("Predict", type='primary'):
38
+ response = requests.post("https://danycontre-final.hf.space/v1/customer", json=customer_data) # enter user name and space name before running the cell
39
+ if response.status_code == 200:
40
+ result = response.json()
41
+ sales_prediction = result["Prediction"] # Extract only the value
42
+ st.write(f"Based on the information provided, the product with ID {Product_Id} will have sales off {sales_prediction}.")
43
+ else:
44
+ st.error("Error in API request")
45
+
46
+ # Batch Prediction
47
+ st.subheader("Batch Prediction")
48
+
49
+ file = st.file_uploader("Upload CSV file", type=["csv"])
50
+ if file is not None:
51
+ if st.button("Predict for Batch", type='primary'):
52
+ response = requests.post("https://danycontre-final.hf.space/v1/customerbatch", files={"file": file}) # enter user name and space name before running the cell
53
+ if response.status_code == 200:
54
+ result = response.json()
55
+ st.header("Batch Prediction Results")
56
+ st.write(result)
57
+ else:
58
+ 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