Upload folder using huggingface_hub
Browse files- Dockerfile +9 -13
- app.py +97 -0
- requirements.txt +6 -3
- uperkart_sales_model_v1_0.joblib +3 -0
Dockerfile
CHANGED
|
@@ -1,20 +1,16 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 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 |
-
|
| 17 |
-
|
| 18 |
-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 19 |
|
| 20 |
-
|
|
|
|
| 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,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import joblib
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# Load the trained model
|
| 8 |
+
@st.cache_resource
|
| 9 |
+
def load_model():
|
| 10 |
+
return joblib.load(saved_model_path)
|
| 11 |
+
|
| 12 |
+
model = load_model()
|
| 13 |
+
|
| 14 |
+
#Streamlit UI for Price Prediction
|
| 15 |
+
st.set_page_config(page_title="SuperKart Sales Predictor", layout='centered')
|
| 16 |
+
st.title("SuperKart Sales Prediction App - By Sriranjan")
|
| 17 |
+
st.write("Input the product and store details below. The app will predict the **Product Store Sales Total** using the trained ML model.")
|
| 18 |
+
|
| 19 |
+
st.markdown("""
|
| 20 |
+
Input the product and store details below. The app will predict the **Product Store Sales Total** using the trained ML model.
|
| 21 |
+
""")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
st.subheader("Enter the listing details:")
|
| 25 |
+
|
| 26 |
+
# Collect user input
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Example options based on your data
|
| 30 |
+
product_sugar_content_options = ['Low Sugar', 'Regular', 'No Sugar', 'reg']
|
| 31 |
+
product_type_options = [
|
| 32 |
+
'Fruits and Vegetables', 'Snack Foods', 'Frozen Foods', 'Dairy', 'Household',
|
| 33 |
+
'Baking Goods', 'Canned', 'Health and Hygiene', 'Meat', 'Soft Drinks',
|
| 34 |
+
'Breads', 'Hard Drinks', 'Others', 'Starchy Foods', 'Breakfast', 'Seafood'
|
| 35 |
+
]
|
| 36 |
+
store_id_options = ['OUT004', 'OUT001', 'OUT003', 'OUT002']
|
| 37 |
+
store_size_options = ['Medium', 'High', 'Small']
|
| 38 |
+
city_type_options = ['Tier 2', 'Tier 1', 'Tier 3']
|
| 39 |
+
store_type_options = ['Supermarket Type2', 'Supermarket Type1', 'Departmental Store', 'Food Mart']
|
| 40 |
+
|
| 41 |
+
# Product Store Sales Total is the target, not an input, so you may exclude it from user input or display stats elsewhere
|
| 42 |
+
|
| 43 |
+
# --- Input widgets ---
|
| 44 |
+
# Numeric feature inputs with min, max, mean values set as constraints/defaults
|
| 45 |
+
product_weight = st.number_input("Product Weight (kg)",min_value=4.0,max_value=22.0, value=1.0,help="Weight of the product in kilograms")
|
| 46 |
+
|
| 47 |
+
product_allocated_area = st.number_input(
|
| 48 |
+
"Product Allocated Area",
|
| 49 |
+
min_value=0.004,
|
| 50 |
+
max_value=0.298,
|
| 51 |
+
value= min_value
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
store_establishment_year = st.number_input(
|
| 55 |
+
"Store Establishment Year",
|
| 56 |
+
min_value=1987,
|
| 57 |
+
max_value=2009,
|
| 58 |
+
value=1987,
|
| 59 |
+
help="Year the store was established"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
product_sugar_content = st.selectbox("Product Sugar Content", product_sugar_content_options)
|
| 64 |
+
product_type = st.selectbox("Product Type", product_type_options)
|
| 65 |
+
store_id = st.selectbox("Store Id", store_id_options)
|
| 66 |
+
store_size = st.selectbox("Store Size", store_size_options)
|
| 67 |
+
city_type = st.selectbox("Store Location City Type", city_type_options)
|
| 68 |
+
store_type = st.selectbox("Store Type", store_type_options)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
# --- Prepare input for prediction ---
|
| 72 |
+
input_dict = {
|
| 73 |
+
"Product_Weight": product_weight,
|
| 74 |
+
"Product_Allocated_Area": product_allocated_area,
|
| 75 |
+
"Store_Establishment_Year": store_est_year,
|
| 76 |
+
"Product_Sugar_Content": sugar_content,
|
| 77 |
+
"Product_Type": product_type,
|
| 78 |
+
"Store_Id": store_id,
|
| 79 |
+
"Store_Size": store_size,
|
| 80 |
+
"Store_Location_City_Type": city_type,
|
| 81 |
+
"Store_Type": store_type
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
input_df = pd.DataFrame([input_dict])
|
| 85 |
+
|
| 86 |
+
st.write("### Input Summary")
|
| 87 |
+
st.write(input_df)
|
| 88 |
+
|
| 89 |
+
# --- Prediction ---
|
| 90 |
+
if st.button("Predict Sales"):
|
| 91 |
+
prediction = model.predict(input_df)
|
| 92 |
+
st.write(f"The predicted Sales is ${np.exp(prediction)[0]
|
| 93 |
+
|
| 94 |
+
st.markdown("""
|
| 95 |
+
---
|
| 96 |
+
*Built by the Sriranjan.*
|
| 97 |
+
""")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
numpy==2.0.2
|
| 3 |
+
scikit-learn==1.6.1
|
| 4 |
+
xgboost==2.1.4
|
| 5 |
+
joblib==1.4.2
|
| 6 |
+
streamlit==1.43.2
|
uperkart_sales_model_v1_0.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:40a8b724a092dd96c6fe6b953b8abc85c8693c4f69c4d90e45123d9b5447ecae
|
| 3 |
+
size 185133
|