Upload folder using huggingface_hub
Browse files- Dockerfile +9 -13
- app.py +77 -0
- requirements.txt +3 -3
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,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# -------------------------
|
| 6 |
+
# SuperKart Streamlit UI
|
| 7 |
+
# -------------------------
|
| 8 |
+
st.title("SuperKart Sales Revenue Predictor")
|
| 9 |
+
|
| 10 |
+
st.markdown("""
|
| 11 |
+
Use this app to predict the **expected sales revenue** for a given product
|
| 12 |
+
based on its characteristics and store details.
|
| 13 |
+
""")
|
| 14 |
+
|
| 15 |
+
# -------------------------
|
| 16 |
+
# Online Prediction Section
|
| 17 |
+
# -------------------------
|
| 18 |
+
st.subheader("Single Product Prediction")
|
| 19 |
+
|
| 20 |
+
# --- Collect user inputs ---
|
| 21 |
+
Product_Weight = st.number_input("Product Weight (in kg)", min_value=0.0, step=0.1)
|
| 22 |
+
Product_Allocated_Area = st.number_input("Product Allocated Area (ratio to total area)", min_value=0.0, step=0.001)
|
| 23 |
+
Product_MRP = st.number_input("Product MRP (Maximum Retail Price)", min_value=0.0, step=0.5)
|
| 24 |
+
|
| 25 |
+
Product_Sugar_Content = st.selectbox(
|
| 26 |
+
"Product Sugar Content",
|
| 27 |
+
["Low Sugar", "Regular", "No Sugar", "reg"]
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
Product_Type = st.selectbox(
|
| 31 |
+
"Product Type",
|
| 32 |
+
[
|
| 33 |
+
"Fruits and Vegetables", "Snack Foods", "Frozen Foods", "Dairy", "Household",
|
| 34 |
+
"Baking Goods", "Canned", "Health and Hygiene", "Meat", "Soft Drinks",
|
| 35 |
+
"Breads", "Hard Drinks", "Others", "Starchy Foods", "Breakfast", "Seafood"
|
| 36 |
+
]
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
Store_Size = st.selectbox("Store Size", ["Medium", "High", "Small"])
|
| 40 |
+
|
| 41 |
+
Store_Location_City_Type = st.selectbox(
|
| 42 |
+
"Store Location City Type",
|
| 43 |
+
["Tier 1", "Tier 2", "Tier 3"]
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
Store_Type = st.selectbox(
|
| 47 |
+
"Store Type",
|
| 48 |
+
["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"]
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# --- Prepare input data ---
|
| 52 |
+
input_data = pd.DataFrame([{
|
| 53 |
+
"Product_Weight": Product_Weight,
|
| 54 |
+
"Product_Allocated_Area": Product_Allocated_Area,
|
| 55 |
+
"Product_MRP": Product_MRP,
|
| 56 |
+
"Product_Sugar_Content": Product_Sugar_Content,
|
| 57 |
+
"Product_Type": Product_Type,
|
| 58 |
+
"Store_Size": Store_Size,
|
| 59 |
+
"Store_Location_City_Type": Store_Location_City_Type,
|
| 60 |
+
"Store_Type": Store_Type
|
| 61 |
+
}])
|
| 62 |
+
|
| 63 |
+
# --- API endpoint (update this to your HF Space URL or local host) ---
|
| 64 |
+
API_URL = "https://dtapkir-SuperkartSalesPredictionFrontend.hf.space/v1/predict-sales"
|
| 65 |
+
|
| 66 |
+
# --- Make prediction ---
|
| 67 |
+
if st.button("Predict Sales Revenue"):
|
| 68 |
+
with st.spinner("Predicting..."):
|
| 69 |
+
response = requests.post(API_URL, json=input_data.to_dict(orient="records")[0])
|
| 70 |
+
if response.status_code == 200:
|
| 71 |
+
prediction = response.json().get('Predicted Sales Revenue (in dollars)', None)
|
| 72 |
+
if prediction:
|
| 73 |
+
st.success(f"Predicted Sales Revenue: **${prediction}**")
|
| 74 |
+
else:
|
| 75 |
+
st.warning("No prediction returned. Check API response.")
|
| 76 |
+
else:
|
| 77 |
+
st.error(f"Error: {response.status_code}. Could not connect to backend API.")
|
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
|