Abhilashu commited on
Commit
6ff767e
·
verified ·
1 Parent(s): d678297

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -13
  2. app.py +79 -0
  3. requirements.txt +4 -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,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import numpy as np
5
+ import requests
6
+
7
+ # Streamlit UI for Sales Prediction
8
+ st.title("Superkart Total Product Sales Prediction App")
9
+ st.write("This tool predicts the sales of SuperKart store's product based on the property details.")
10
+
11
+ st.subheader("Enter the details:")
12
+
13
+ # Collect user input for each feature
14
+ product_id = st.selectbox("Product ID", ["FD", "NC", "DR"])
15
+ product_weight = st.number_input("Product Weight", min_value=0.0, value=10.0, step=0.1)
16
+ product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
17
+ product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, value=0.05, step=0.01)
18
+ product_mrp = st.number_input("Product MRP", min_value=0.0, value=100.0, step=0.1)
19
+ store_id = st.selectbox("Store ID", ["OUT001", "OUT002", "OUT003", "OUT004"])
20
+ store_establishment_year = st.number_input("Store Establishment Year", min_value=1985, max_value=2025, value=2000, step=1)
21
+ store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
22
+ store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
23
+ store_type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"])
24
+ grouped_product_type = st.selectbox("Grouped Product Type", ["Food Items", "Household and Hygiene", "Beverages", "Miscellaneous"])
25
+
26
+
27
+ # Convert user input into a DataFrame
28
+ input_data = pd.DataFrame([{
29
+ 'Product_Weight': product_weight,
30
+ 'Product_Allocated_Area': product_allocated_area,
31
+ 'Product_MRP': product_mrp,
32
+ 'Product_Id_FD': 1 if product_id == 'FD' else 0,
33
+ 'Product_Id_NC': 1 if product_id == 'NC' else 0,
34
+ 'Product_Sugar_Content_No Sugar': 1 if product_sugar_content == 'No Sugar' else 0,
35
+ 'Product_Sugar_Content_Regular': 1 if product_sugar_content == 'Regular' else 0,
36
+ 'Store_Id_OUT002': 1 if store_id == 'OUT002' else 0,
37
+ 'Store_Id_OUT003': 1 if store_id == 'OUT003' else 0,
38
+ 'Store_Id_OUT004': 1 if store_id == 'OUT004' else 0,
39
+ 'Store_Size_Medium': 1 if store_size == 'Medium' else 0,
40
+ 'Store_Size_Small': 1 if store_size == 'Small' else 0,
41
+ 'Store_Location_City_Type_Tier 2': 1 if store_location_city_type == 'Tier 2' else 0,
42
+ 'Store_Location_City_Type_Tier 3': 1 if store_location_city_type == 'Tier 3' else 0,
43
+ 'Store_Type_Food Mart': 1 if store_type == 'Food Mart' else 0,
44
+ 'Store_Type_Supermarket Type1': 1 if store_type == 'Supermarket Type1' else 0,
45
+ 'Store_Type_Supermarket Type2': 1 if store_type == 'Supermarket Type2' else 0,
46
+ 'Grouped_Product_Type_Food Items': 1 if grouped_product_type == 'Food Items' else 0,
47
+ 'Grouped_Product_Type_Household and Hygiene': 1 if grouped_product_type == 'Household and Hygiene' else 0,
48
+ 'Grouped_Product_Type_Miscellaneous': 1 if grouped_product_type == 'Miscellaneous' else 0,
49
+ 'Store_Age': 2025 - store_establishment_year # Calculate Store_Age
50
+ }])
51
+
52
+ # Ensure all columns used during training are present in the input_data DataFrame
53
+ # Add dummy columns for any missing one-hot encoded features
54
+ train_cols = ['Product_Weight', 'Product_Allocated_Area', 'Product_MRP', 'Store_Age',
55
+ 'Product_Id_FD', 'Product_Id_NC', 'Product_Sugar_Content_No Sugar',
56
+ 'Product_Sugar_Content_Regular', 'Store_Id_OUT002', 'Store_Id_OUT003',
57
+ 'Store_Id_OUT004', 'Store_Size_Medium', 'Store_Size_Small',
58
+ 'Store_Location_City_Type_Tier 2', 'Store_Location_City_Type_Tier 3',
59
+ 'Store_Type_Food Mart', 'Store_Type_Supermarket Type1',
60
+ 'Store_Type_Supermarket Type2', 'Grouped_Product_Type_Food Items',
61
+ 'Grouped_Product_Type_Household and Hygiene',
62
+ 'Grouped_Product_Type_Miscellaneous']
63
+
64
+ for col in train_cols:
65
+ if col not in input_data.columns:
66
+ input_data[col] = 0
67
+
68
+ # Reorder columns to match the training data
69
+ input_data = input_data[train_cols]
70
+
71
+
72
+ # Predict button
73
+ if st.button("Predict"):
74
+ response = requests.post("https://Abhilashu/superKart_Total_Sales_Prediction_Backend.hf.space/v1/rental", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
75
+ if response.status_code == 200:
76
+ prediction = response.json()['Predicted total sales (in dollars)']
77
+ st.success(f"The predicted total sales for this product in this store is: {prediction[0]:.2f}")
78
+ else:
79
+ st.error("Error making prediction.")
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
- altair
2
- pandas
3
- streamlit
 
 
1
+ pandas==2.2.2
2
+ numpy==2.0.2
3
+ requests==2.28.1
4
+ streamlit==1.43.2