Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- DockerFile +24 -0
- DockerFileUI +24 -0
- app.py +2 -12
- requirements.txt +2 -2
- requirementsUI.txt +4 -0
- streamlit_app.py +49 -0
DockerFile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Base image with Python
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set environment variables
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
+
ENV PORT=7860
|
| 8 |
+
|
| 9 |
+
# Set working directory
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
# Copy files
|
| 13 |
+
COPY requirements.txt .
|
| 14 |
+
COPY app.py .
|
| 15 |
+
COPY super_kart_prediction_model_v1_0.joblib .
|
| 16 |
+
|
| 17 |
+
# Install dependencies
|
| 18 |
+
RUN pip install --upgrade pip && pip install -r requirements.txt
|
| 19 |
+
|
| 20 |
+
# Expose the Streamlit port
|
| 21 |
+
EXPOSE 7860
|
| 22 |
+
|
| 23 |
+
# Run the Streamlit app on port 7860 (as required by Hugging Face)
|
| 24 |
+
CMD streamlit run app.py --server.port 7860 --server.address 0.0.0.0
|
DockerFileUI
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Base image with Python
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set environment variables
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
+
ENV PORT=7860
|
| 8 |
+
|
| 9 |
+
# Set working directory
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
# Copy files
|
| 13 |
+
COPY requirementsUI.txt .
|
| 14 |
+
COPY streamlit_app.py .
|
| 15 |
+
COPY super_kart_prediction_model_v1_0.joblib .
|
| 16 |
+
|
| 17 |
+
# Install dependencies
|
| 18 |
+
RUN pip install --upgrade pip && pip install -r requirementsUI.txt
|
| 19 |
+
|
| 20 |
+
# Expose the Streamlit port
|
| 21 |
+
EXPOSE 7860
|
| 22 |
+
|
| 23 |
+
# Run the Streamlit app on port 7860 (as required by Hugging Face)
|
| 24 |
+
CMD streamlit run streamlit_app.py --server.port 7860 --server.address 0.0.0.0
|
app.py
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
import joblib
|
| 3 |
import pandas as pd
|
| 4 |
-
import os
|
| 5 |
-
import numpy
|
| 6 |
-
import sklearn.compose._column_transformer
|
| 7 |
-
class _RemainderColsList(list): pass
|
| 8 |
-
sklearn.compose._column_transformer._RemainderColsList = _RemainderColsList
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
# Optional: ignore ComplexWarnings if they’re not needed
|
| 12 |
-
import warnings
|
| 13 |
-
warnings.filterwarnings("ignore", category=UserWarning) # Or remove entirely
|
| 14 |
|
| 15 |
# Load the trained model pipeline
|
| 16 |
-
|
| 17 |
-
model = joblib.load(model_path)
|
| 18 |
|
| 19 |
# Initialize the Flask app
|
| 20 |
app = Flask(__name__)
|
|
|
|
| 1 |
+
# Define the backend
|
| 2 |
from flask import Flask, request, jsonify
|
| 3 |
import joblib
|
| 4 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Load the trained model pipeline
|
| 7 |
+
model = joblib.load("deployment_files/super_kart_prediction_model_v1_0.joblib")
|
|
|
|
| 8 |
|
| 9 |
# Initialize the Flask app
|
| 10 |
app = Flask(__name__)
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
flask
|
| 2 |
-
scikit-learn
|
| 3 |
pandas
|
| 4 |
-
numpy
|
| 5 |
xgboost
|
| 6 |
joblib
|
|
|
|
| 1 |
flask
|
| 2 |
+
scikit-learn
|
| 3 |
pandas
|
| 4 |
+
numpy
|
| 5 |
xgboost
|
| 6 |
joblib
|
requirementsUI.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|
| 3 |
+
scikit-learn
|
| 4 |
+
joblib
|
streamlit_app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
# Load the trained model
|
| 6 |
+
model = joblib.load("super_kart_prediction_model_v1_0.joblib")
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="SuperKart Sales Predictor", layout="centered")
|
| 9 |
+
|
| 10 |
+
st.title("SuperKart Product Sales Prediction")
|
| 11 |
+
|
| 12 |
+
# --- Input form ---
|
| 13 |
+
with st.form("prediction_form"):
|
| 14 |
+
col1, col2 = st.columns(2)
|
| 15 |
+
|
| 16 |
+
with col1:
|
| 17 |
+
product_weight = st.slider("Product Weight (kg)", 0.0, 25.0, 10.0)
|
| 18 |
+
allocated_area = st.slider("Allocated Area (sq ft)", 50.0, 1000.0, 200.0)
|
| 19 |
+
product_mrp = st.number_input("Product MRP (₹)", min_value=10.0, max_value=500.0, value=250.0)
|
| 20 |
+
|
| 21 |
+
with col2:
|
| 22 |
+
sugar_content = st.selectbox("Sugar Content", ["Low", "Medium", "High"])
|
| 23 |
+
product_type = st.selectbox("Product Type", ["Snack Foods", "Baking Goods", "Canned", "Soft Drinks", "Dairy"])
|
| 24 |
+
store_year = st.selectbox("Store Establishment Year", list(range(1985, 2024)))
|
| 25 |
+
|
| 26 |
+
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 27 |
+
city_type = st.selectbox("Store Location City Type", ["Urban", "Semi-Urban", "Rural"])
|
| 28 |
+
store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Grocery Store", "Supermarket Type3"])
|
| 29 |
+
|
| 30 |
+
submitted = st.form_submit_button("Predict")
|
| 31 |
+
|
| 32 |
+
# --- Predict ---
|
| 33 |
+
if submitted:
|
| 34 |
+
# Create input DataFrame
|
| 35 |
+
input_data = pd.DataFrame([{
|
| 36 |
+
"Product_Weight": product_weight,
|
| 37 |
+
"Product_Sugar_Content": sugar_content,
|
| 38 |
+
"Product_Allocated_Area": allocated_area,
|
| 39 |
+
"Product_Type": product_type,
|
| 40 |
+
"Product_MRP": product_mrp,
|
| 41 |
+
"Store_Establishment_Year": store_year,
|
| 42 |
+
"Store_Size": store_size,
|
| 43 |
+
"Store_Location_City_Type": city_type,
|
| 44 |
+
"Store_Type": store_type
|
| 45 |
+
}])
|
| 46 |
+
|
| 47 |
+
# Make prediction
|
| 48 |
+
prediction = model.predict(input_data)[0]
|
| 49 |
+
st.success(f"📈 Predicted Product Sales: ₹{round(prediction, 2)}")
|