Upload folder using huggingface_hub
Browse files- Dockerfile +8 -13
- app.py +114 -0
- requirements.txt +3 -3
Dockerfile
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
curl \
|
| 8 |
-
software-properties-common \
|
| 9 |
-
git \
|
| 10 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
-
|
| 12 |
-
COPY requirements.txt ./
|
| 13 |
-
COPY src/ ./src/
|
| 14 |
|
|
|
|
| 15 |
RUN pip3 install -r requirements.txt
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 20 |
|
| 21 |
-
|
|
|
|
| 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,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
import numpy as np
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
|
| 7 |
+
# Load the trained model
|
| 8 |
+
@st.cache_resource
|
| 9 |
+
def load_model():
|
| 10 |
+
return joblib.load("SuperKart_model_v1_0.joblib")
|
| 11 |
+
|
| 12 |
+
model = load_model()
|
| 13 |
+
|
| 14 |
+
# Streamlit UI for Sales Prediction
|
| 15 |
+
st.title("Retail Product Sales Prediction App")
|
| 16 |
+
st.write("This tool predicts the total sales for a product in a retail store based on product and store characteristics.")
|
| 17 |
+
|
| 18 |
+
st.subheader("Enter the product and store details:")
|
| 19 |
+
|
| 20 |
+
# Create two columns for better layout
|
| 21 |
+
col1, col2 = st.columns(2)
|
| 22 |
+
|
| 23 |
+
with col1:
|
| 24 |
+
# Product Features
|
| 25 |
+
st.markdown("**Product Details**")
|
| 26 |
+
product_weight = st.slider("Product Weight (kg)", 4.0, 22.0, 12.66, 0.01)
|
| 27 |
+
product_sugar = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
|
| 28 |
+
product_area = st.slider("Allocated Area (sqm)", 0.004, 0.3, 0.05, 0.001)
|
| 29 |
+
product_type = st.selectbox("Product Type", [
|
| 30 |
+
"Frozen Foods", "Dairy", "Canned", "Baking Goods",
|
| 31 |
+
"Health and Hygiene", "Snack Foods", "Meat", "Household"
|
| 32 |
+
])
|
| 33 |
+
product_mrp = st.slider("Product MRP (price)", 31.0, 266.0, 147.0, 0.5)
|
| 34 |
+
|
| 35 |
+
with col2:
|
| 36 |
+
# Store Features
|
| 37 |
+
st.markdown("**Store Details**")
|
| 38 |
+
store_id = st.selectbox("Store ID", ["OUT001", "OUT002", "OUT003", "OUT004"])
|
| 39 |
+
current_year = datetime.now().year
|
| 40 |
+
establishment_year = st.slider("Store Establishment Year",
|
| 41 |
+
1987, current_year, 2002)
|
| 42 |
+
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 43 |
+
city_type = st.selectbox("City Tier", ["Tier 1", "Tier 2", "Tier 3"])
|
| 44 |
+
store_type = st.selectbox("Store Type", [
|
| 45 |
+
"Supermarket Type1", "Supermarket Type2",
|
| 46 |
+
"Departmental Store", "Food Mart"
|
| 47 |
+
])
|
| 48 |
+
|
| 49 |
+
# Calculate derived features
|
| 50 |
+
store_age = current_year - establishment_year
|
| 51 |
+
product_density = product_weight / (product_area + 1e-6)
|
| 52 |
+
price_per_weight = product_mrp / (product_weight + 1e-6)
|
| 53 |
+
|
| 54 |
+
# Convert user input into a DataFrame
|
| 55 |
+
input_data = pd.DataFrame([{
|
| 56 |
+
'Product_Weight': product_weight,
|
| 57 |
+
'Product_Sugar_Content': product_sugar,
|
| 58 |
+
'Product_Allocated_Area': product_area,
|
| 59 |
+
'Product_Type': product_type,
|
| 60 |
+
'Product_MRP': product_mrp,
|
| 61 |
+
'Store_Id': store_id,
|
| 62 |
+
'Store_Establishment_Year': establishment_year,
|
| 63 |
+
'Store_Size': store_size,
|
| 64 |
+
'Store_Location_City_Type': city_type,
|
| 65 |
+
'Store_Type': store_type,
|
| 66 |
+
'Store_Age': store_age,
|
| 67 |
+
'Product_Density': product_density,
|
| 68 |
+
'Price_Per_Unit_Weight': price_per_weight,
|
| 69 |
+
'Product_Size_Category': 'Small' if product_weight <= 10 else ('Medium' if product_weight <= 15 else 'Large'),
|
| 70 |
+
'Store_Tier_Size': f"{city_type}_{store_size}"
|
| 71 |
+
}])
|
| 72 |
+
|
| 73 |
+
# Predict button
|
| 74 |
+
if st.button("Predict Sales"):
|
| 75 |
+
try:
|
| 76 |
+
prediction = model.predict(input_data)
|
| 77 |
+
st.success(f"Predicted Sales Total: ${prediction[0]:.2f}")
|
| 78 |
+
|
| 79 |
+
# Show some statistics
|
| 80 |
+
st.subheader("Statistics")
|
| 81 |
+
st.write(f"Store Age: {store_age} years")
|
| 82 |
+
st.write(f"Product Density: {product_density:.2f} kg/sqm")
|
| 83 |
+
st.write(f"Price per Unit Weight: ${price_per_weight:.2f}/kg")
|
| 84 |
+
|
| 85 |
+
except Exception as e:
|
| 86 |
+
st.error(f"Error in prediction: {str(e)}")
|
| 87 |
+
|
| 88 |
+
# Add some helpful information
|
| 89 |
+
st.sidebar.markdown("""
|
| 90 |
+
**Data Statistics:**
|
| 91 |
+
- Average Product Weight: 12.65 kg
|
| 92 |
+
- Average Allocated Area: 0.07 sqm
|
| 93 |
+
- Average MRP: $147.03
|
| 94 |
+
- Average Sales: $3464.00
|
| 95 |
+
""")
|
| 96 |
+
|
| 97 |
+
# Add a sample data button
|
| 98 |
+
if st.sidebar.button("Load Sample Data"):
|
| 99 |
+
sample_data = {
|
| 100 |
+
'Product_Weight': 12.66,
|
| 101 |
+
'Product_Sugar_Content': "Low Sugar",
|
| 102 |
+
'Product_Allocated_Area': 0.027,
|
| 103 |
+
'Product_Type': "Frozen Foods",
|
| 104 |
+
'Product_MRP': 117.08,
|
| 105 |
+
'Store_Id': "OUT004",
|
| 106 |
+
'Store_Establishment_Year': 2009,
|
| 107 |
+
'Store_Size': "Medium",
|
| 108 |
+
'Store_Location_City_Type': "Tier 2",
|
| 109 |
+
'Store_Type': "Supermarket Type2"
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
# Update all widgets with sample data
|
| 113 |
+
st.experimental_set_query_params(**sample_data)
|
| 114 |
+
st.experimental_rerun()
|
requirements.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
streamlit
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|
| 3 |
+
streamlit==1.43.2
|