Upload folder using huggingface_hub
Browse files- Dockerfile +15 -12
- app.py +70 -0
- requirements.txt +6 -3
Dockerfile
CHANGED
|
@@ -1,20 +1,23 @@
|
|
| 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 |
-
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
| 1 |
+
# Use a minimal base image with Python 3.9 installed
|
| 2 |
+
FROM python:3.9
|
| 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 |
+
RUN useradd -m -u 1000 user
|
| 14 |
+
USER user
|
| 15 |
+
ENV HOME=/home/user \
|
| 16 |
+
PATH=/home/user/.local/bin:$PATH
|
| 17 |
+
|
| 18 |
+
WORKDIR $HOME/app
|
| 19 |
|
| 20 |
+
COPY --chown=user . $HOME/app
|
| 21 |
|
| 22 |
+
# Define the command to run the Streamlit app on port "8501" and make it accessible externally
|
| 23 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
app.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import joblib
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# -------------------------
|
| 8 |
+
# Configuration
|
| 9 |
+
# -------------------------
|
| 10 |
+
HF_MODEL_REPO = "VIKASHRAM/superkart"
|
| 11 |
+
MODEL_FILENAME = "best_model_v1.joblib"
|
| 12 |
+
|
| 13 |
+
# -------------------------
|
| 14 |
+
# Download & load model
|
| 15 |
+
# -------------------------
|
| 16 |
+
model = None
|
| 17 |
+
try:
|
| 18 |
+
model_path = hf_hub_download(repo_id=HF_MODEL_REPO, filename=MODEL_FILENAME, repo_type="model", token=os.getenv("HF_TOKEN"))
|
| 19 |
+
model = joblib.load(model_path)
|
| 20 |
+
st.write(f"Loaded model from Hugging Face: {HF_MODEL_REPO}/{MODEL_FILENAME}")
|
| 21 |
+
except Exception as e:
|
| 22 |
+
st.warning(f"Could not download model from Hugging Face ({HF_MODEL_REPO}).\nError: {e}\nFalling back to local file if present.")
|
| 23 |
+
if os.path.exists(MODEL_FILENAME):
|
| 24 |
+
model = joblib.load(MODEL_FILENAME)
|
| 25 |
+
st.write(f"Loaded local model file: {MODEL_FILENAME}")
|
| 26 |
+
else:
|
| 27 |
+
st.error("Model not available. Please upload the model to HF or place it locally.")
|
| 28 |
+
st.stop()
|
| 29 |
+
|
| 30 |
+
# -------------------------
|
| 31 |
+
# Streamlit UI
|
| 32 |
+
# -------------------------
|
| 33 |
+
st.title("SuperKart Sales Prediction App")
|
| 34 |
+
st.write("Predict product sales at different stores using trained ML model.")
|
| 35 |
+
|
| 36 |
+
# --- Customer details
|
| 37 |
+
Product_Weight = st.number_input("Product Weight", value=12.66)
|
| 38 |
+
Product_Sugar_Content = st.selectbox("Sugar Content", ["Low Sugar","No Sugar","Medium Sugar","High Sugar"])
|
| 39 |
+
Product_Allocated_Area = st.number_input("Allocated Area", value=0.027, step=0.001, format="%.3f")
|
| 40 |
+
Product_Type = st.text_input("Product Type", "Frozen Foods")
|
| 41 |
+
Product_MRP = st.number_input("Product MRP", value=117.08)
|
| 42 |
+
Store_Id = st.text_input("Store Id", "OUT004")
|
| 43 |
+
Store_Establishment_Year = st.number_input("Store Establishment Year", value=2009, step=1)
|
| 44 |
+
Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 45 |
+
Store_Location_City_Type = st.selectbox("Store City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 46 |
+
Store_Type = st.text_input("Store Type", "Supermarket Type2")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# Assemble input into DataFrame matching training columns (raw — pipeline should handle preprocessing)
|
| 50 |
+
input_df = pd.DataFrame([{
|
| 51 |
+
"Product_Weight": Product_Weight,
|
| 52 |
+
"Product_Sugar_Content": Product_Sugar_Content,
|
| 53 |
+
"Product_Allocated_Area": Product_Allocated_Area,
|
| 54 |
+
"Product_Type": Product_Type,
|
| 55 |
+
"Product_MRP": Product_MRP,
|
| 56 |
+
"Store_Id": Store_Id,
|
| 57 |
+
"Store_Establishment_Year": Store_Establishment_Year,
|
| 58 |
+
"Store_Size": Store_Size,
|
| 59 |
+
"Store_Location_City_Type": Store_Location_City_Type,
|
| 60 |
+
"Store_Type": Store_Type
|
| 61 |
+
}])
|
| 62 |
+
|
| 63 |
+
st.subheader("Input Preview")
|
| 64 |
+
st.dataframe(input_df.T, width=700)
|
| 65 |
+
|
| 66 |
+
# Prediction
|
| 67 |
+
if st.button("Predict Sales"):
|
| 68 |
+
prediction = model.predict(input_df)
|
| 69 |
+
st.subheader("Prediction Result")
|
| 70 |
+
st.write(f"Predicted Product Store Sales Total: {prediction[0]:.2f}")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
streamlit
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
huggingface_hub==0.32.6
|
| 3 |
+
streamlit==1.43.2
|
| 4 |
+
joblib==1.5.1
|
| 5 |
+
scikit-learn==1.6.0
|
| 6 |
+
xgboost==2.1.4
|