Spaces:
Build error
Build error
Upload 3 files
Browse files- Dockerfile +16 -0
- app.py +88 -0
- requirements.txt +10 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Load the trained Random Forest pipeline model
|
| 7 |
+
try:
|
| 8 |
+
model = joblib.load('random_forest_pipeline.pkl')
|
| 9 |
+
except FileNotFoundError:
|
| 10 |
+
st.error("Model file 'random_forest_pipeline.pkl' not found. Please ensure the model is trained and saved.")
|
| 11 |
+
model = None
|
| 12 |
+
|
| 13 |
+
st.title('SuperKart Sales Prediction App')
|
| 14 |
+
|
| 15 |
+
if model:
|
| 16 |
+
st.sidebar.header('Input Features')
|
| 17 |
+
|
| 18 |
+
# Define input fields for each feature based on your dataset columns
|
| 19 |
+
# Product_Weight
|
| 20 |
+
product_weight = st.sidebar.number_input('Product Weight(kg)', min_value=0.1, max_value=30.0, value=10.0)
|
| 21 |
+
|
| 22 |
+
# Product_Sugar_Content
|
| 23 |
+
sugar_content_options = ['Low Sugar', 'Regular', 'No Sugar', 'reg'] # Based on EDA
|
| 24 |
+
product_sugar_content = st.sidebar.selectbox('Product Sugar Content', sugar_content_options)
|
| 25 |
+
|
| 26 |
+
# Product_Allocated_Area
|
| 27 |
+
product_allocated_area = st.sidebar.number_input('Product Allocated Area (sq. m)', min_value=0.0, max_value=1.0, value=0.05)
|
| 28 |
+
|
| 29 |
+
# Product_Type
|
| 30 |
+
product_type_options = ['Breads', 'Snack Foods', 'Frozen Foods', 'Dairy', 'Seafood', 'Starchy Foods', 'Soft Drinks', 'Meat', 'Hard Drinks', 'Health and Hygiene', 'Baking Goods', 'Breakfast', 'Canned', 'Fruits and Vegetables', 'Household', 'Others'] # Based on EDA
|
| 31 |
+
product_type = st.sidebar.selectbox('Product Type', product_type_options)
|
| 32 |
+
|
| 33 |
+
# Product_MRP
|
| 34 |
+
product_mrp = st.sidebar.number_input('Product MRP ($)', min_value=10.0, max_value=300.0, value=150.0)
|
| 35 |
+
|
| 36 |
+
# Store_Id - Using an example list, replace with actual Store IDs from your data if possible
|
| 37 |
+
store_id_options = ['OUT027', 'OUT013', 'OUT011', 'OUT010', 'OUT004', 'OUT001', 'OUT002', 'OUT003']
|
| 38 |
+
store_id = st.sidebar.selectbox('Store ID', store_id_options)
|
| 39 |
+
|
| 40 |
+
# Store_Establishment_Year
|
| 41 |
+
store_establishment_year = st.sidebar.number_input('Store Establishment Year', min_value=1900, max_value=2024, value=2000)
|
| 42 |
+
|
| 43 |
+
# Store_Size
|
| 44 |
+
store_size_options = ['Medium', 'High', 'Low']
|
| 45 |
+
store_size = st.sidebar.selectbox('Store Size', store_size_options)
|
| 46 |
+
|
| 47 |
+
# Store_Location_City_Type
|
| 48 |
+
city_type_options = ['Tier 1', 'Tier 2', 'Tier 3']
|
| 49 |
+
store_location_city_type = st.sidebar.selectbox('Store Location City Type', city_type_options)
|
| 50 |
+
|
| 51 |
+
# Store_Type
|
| 52 |
+
store_type_options = ['Departmental Store', 'Supermarket Type 1', 'Supermarket Type 2', 'Food Mart']
|
| 53 |
+
store_type = st.sidebar.selectbox('Store Type', store_type_options)
|
| 54 |
+
|
| 55 |
+
# Product_Id - Although not used in the model, it's in the original data structure
|
| 56 |
+
# For prediction, we can use a placeholder or a dummy value if not strictly needed by the preprocessor
|
| 57 |
+
product_id = 'dummy_product_id' # Placeholder
|
| 58 |
+
|
| 59 |
+
# Create a DataFrame with the input features
|
| 60 |
+
input_data = pd.DataFrame({
|
| 61 |
+
'Product_Id': [product_id],
|
| 62 |
+
'Product_Weight': [product_weight],
|
| 63 |
+
'Product_Sugar_Content': [product_sugar_content],
|
| 64 |
+
'Product_Allocated_Area': [product_allocated_area],
|
| 65 |
+
'Product_Type': [product_type],
|
| 66 |
+
'Product_MRP': [product_mrp],
|
| 67 |
+
'Store_Id': [store_id],
|
| 68 |
+
'Store_Establishment_Year': [store_establishment_year],
|
| 69 |
+
'Store_Size': [store_size],
|
| 70 |
+
'Store_Location_City_Type': [store_location_city_type],
|
| 71 |
+
'Store_Type': [store_type]
|
| 72 |
+
})
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
st.subheader('Input Data')
|
| 76 |
+
st.write(input_data)
|
| 77 |
+
|
| 78 |
+
# Make prediction
|
| 79 |
+
if st.sidebar.button('Predict Sales'):
|
| 80 |
+
try:
|
| 81 |
+
prediction = model.predict(input_data)
|
| 82 |
+
st.subheader('Predicted Product Store Sales Total')
|
| 83 |
+
st.success(f'Predicted Sales: ${prediction[0]:,.2f}')
|
| 84 |
+
except Exception as e:
|
| 85 |
+
st.error(f"An error occurred during prediction: {e}")
|
| 86 |
+
|
| 87 |
+
else:
|
| 88 |
+
st.warning("Model not loaded. Please ensure the model file exists and the pipeline is correctly defined.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy==2.0.2
|
| 2 |
+
pandas==2.2.2
|
| 3 |
+
scikit-learn==1.6.1
|
| 4 |
+
matplotlib==3.10.0
|
| 5 |
+
seaborn==0.13.2
|
| 6 |
+
joblib==1.4.2
|
| 7 |
+
xgboost==2.1.4
|
| 8 |
+
requests==2.32.3
|
| 9 |
+
huggingface_hub==0.30.1
|
| 10 |
+
streamlit==1.37.0
|