Upload folder using huggingface_hub
Browse files- Dockerfile +9 -13
- app.py +72 -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,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Set the title of the Streamlit app
|
| 6 |
+
st.title("SuperKart Sales Prediction App")
|
| 7 |
+
st.write("This application predicts the total sales of a product in a SuperKart store.")
|
| 8 |
+
|
| 9 |
+
# Backend API URL
|
| 10 |
+
BACKEND_URL = "https://rakeshunnee-SuperKartSalesPredictionBackend.hf.space"
|
| 11 |
+
|
| 12 |
+
# Section for online prediction
|
| 13 |
+
st.subheader("Online Prediction")
|
| 14 |
+
|
| 15 |
+
# Collect user input for SuperKart features
|
| 16 |
+
product_weight = st.number_input("Product Weight", min_value=4.0, max_value=22.0, value=12.66, step=0.01)
|
| 17 |
+
product_sugar_content = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar', 'reg'])
|
| 18 |
+
product_allocated_area = st.number_input("Product Allocated Area (ratio)", min_value=0.004, max_value=0.298, value=0.06, step=0.001)
|
| 19 |
+
product_type = st.selectbox("Product Type", ['Fruits and Vegetables', 'Snack Foods', 'Frozen Foods', 'Dairy', 'Household', 'Baking Goods', 'Canned', 'Health and Hygiene', 'Meat', 'Soft Drinks', 'Breads', 'Hard Drinks', 'Others', 'Starchy Foods', 'Breakfast', 'Seafood'])
|
| 20 |
+
product_mrp = st.number_input("Product MRP", min_value=31.0, max_value=266.0, value=147.0, step=0.01)
|
| 21 |
+
store_establishment_year = st.number_input("Store Establishment Year", min_value=1987, max_value=2009, value=1999, format="%d")
|
| 22 |
+
store_size = st.selectbox("Store Size", ['Medium', 'High', 'Small'])
|
| 23 |
+
store_location_city_type = st.selectbox("Store Location City Type", ['Tier 2', 'Tier 1', 'Tier 3'])
|
| 24 |
+
store_type = st.selectbox("Store Type", ['Supermarket Type2', 'Departmental Store', 'Supermarket Type1', 'Food Mart'])
|
| 25 |
+
|
| 26 |
+
# Create a dictionary for the single prediction request
|
| 27 |
+
single_prediction_data = {
|
| 28 |
+
'Product_Weight': product_weight,
|
| 29 |
+
'Product_Sugar_Content': product_sugar_content,
|
| 30 |
+
'Product_Allocated_Area': product_allocated_area,
|
| 31 |
+
'Product_Type': product_type,
|
| 32 |
+
'Product_MRP': product_mrp,
|
| 33 |
+
'Store_Establishment_Year': store_establishment_year,
|
| 34 |
+
'Store_Size': store_size,
|
| 35 |
+
'Store_Location_City_Type': store_location_city_type,
|
| 36 |
+
'Store_Type': store_type
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
# Make prediction when the "Predict" button is clicked
|
| 40 |
+
if st.button("Predict Product Sales"):
|
| 41 |
+
try:
|
| 42 |
+
response = requests.post(f"{BACKEND_URL}/v1/predict-sales", json=single_prediction_data)
|
| 43 |
+
response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)
|
| 44 |
+
prediction = response.json()['Predicted Product Store Sales Total']
|
| 45 |
+
st.success(f"Predicted Product Store Sales Total: ₹{prediction:.2f}")
|
| 46 |
+
except requests.exceptions.RequestException as e:
|
| 47 |
+
st.error(f"Error making online prediction: {e}")
|
| 48 |
+
except KeyError:
|
| 49 |
+
st.error("Could not parse prediction from response. Please check backend logs.")
|
| 50 |
+
except Exception as e:
|
| 51 |
+
st.error(f"An unexpected error occurred: {e}")
|
| 52 |
+
|
| 53 |
+
# Section for batch prediction
|
| 54 |
+
st.subheader("Batch Prediction (Upload CSV)")
|
| 55 |
+
|
| 56 |
+
# Allow users to upload a CSV file for batch prediction
|
| 57 |
+
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
| 58 |
+
|
| 59 |
+
# Make batch prediction when the "Predict Batch" button is clicked
|
| 60 |
+
if uploaded_file is not None:
|
| 61 |
+
if st.button("Predict Batch Sales"):
|
| 62 |
+
try:
|
| 63 |
+
files = {'file': uploaded_file.getvalue()}
|
| 64 |
+
response = requests.post(f"{BACKEND_URL}/v1/predict-sales-batch", files=files)
|
| 65 |
+
response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)
|
| 66 |
+
predictions = response.json()
|
| 67 |
+
st.success("Batch predictions completed!")
|
| 68 |
+
st.write(pd.DataFrame(predictions.items(), columns=['Prediction ID', 'Predicted Sales']))
|
| 69 |
+
except requests.exceptions.RequestException as e:
|
| 70 |
+
st.error(f"Error making batch prediction: {e}")
|
| 71 |
+
except Exception as e:
|
| 72 |
+
st.error(f"An unexpected error occurred: {e}")
|
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
|