Upload folder using huggingface_hub
Browse files- Dockerfile +16 -0
- app.py +64 -0
- gradient_tuned.joblib +3 -0
- requirements.txt +6 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 pip install --no-cache-dir -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,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# Title of the Streamlit app
|
| 6 |
+
st.title("Product Sales Prediction for Stores")
|
| 7 |
+
|
| 8 |
+
# Section for single product prediction
|
| 9 |
+
st.subheader("Please fill details below for sales prediction")
|
| 10 |
+
|
| 11 |
+
# Input fields for user to provide single product/store details
|
| 12 |
+
Product_Weight = st.number_input("Product_Weight (Weight of the product)", min_value=1, max_value=50,value=10.0)
|
| 13 |
+
Product_Sugar_Content = st.selectbox("Product_Sugar_Content (Select the sugar content level of the product)", ['Low Sugar','Regular','No Sugar'])
|
| 14 |
+
Product_Allocated_Area = st.number_input("Product_Allocated_Area (Area allocated for the product)", min_value=0.001,max_value=0.5,value=0.1)
|
| 15 |
+
Product_Type = st.selectbox("Product_Type (Select the type of product)", ['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'])
|
| 16 |
+
Product_MRP = st.number_input("Product_MRP (Enter the price of the product)", min_value=1,max_value=1000,value=100)
|
| 17 |
+
Store_Id = st.selectbox("Store_Id (Select the Store ID)", ['OUT001','OUT002','OUT003','OUT004'])
|
| 18 |
+
Store_Establishment_Year = st.selectbox("Store_Establishment_Year (Select the year the store was established)", [2009,1987,1999,1998])
|
| 19 |
+
Store_Size = st.selectbox("Store_Size (Select the store size)", ["Medium", "High","Small"])
|
| 20 |
+
Store_Location_City_Type = st.selectbox("Store_Location_City_Type (Select the type of city where the store is located)", ["Tier 2", "Tier 1","Tier 3"])
|
| 21 |
+
Store_Type = st.selectbox("Store_Type (Select the type of store)",['Supermarket Type2','Supermarket Type1','Departmental Store','Food Mart'])
|
| 22 |
+
|
| 23 |
+
# Prepare the payload to send to the backend API
|
| 24 |
+
sales_data = {
|
| 25 |
+
'Product_Weight': Product_Weight,
|
| 26 |
+
'Product_Sugar_Content': Product_Sugar_Content,
|
| 27 |
+
'Product_Allocated_Area': Product_Allocated_Area,
|
| 28 |
+
'Product_Type': Product_Type,
|
| 29 |
+
'Product_MRP': Product_MRP,
|
| 30 |
+
'Store_Id': Store_Id,
|
| 31 |
+
'Store_Size': Store_Size,
|
| 32 |
+
'Store_Location_City_Type': Store_Location_City_Type,
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
# When the "Predict" button is clicked, send a POST request to the backend API
|
| 36 |
+
if st.button("Predict", type='primary'):
|
| 37 |
+
response = requests.post("https://parthipan00410-salespredictionbackend.hf.space/v1/salesdata", json=sales_data)
|
| 38 |
+
|
| 39 |
+
# If the request is successful, display the predicted sales
|
| 40 |
+
if response.status_code == 200:
|
| 41 |
+
result = response.json()
|
| 42 |
+
sales_prediciton = result["predicted_sales"]
|
| 43 |
+
st.write(f"Here is the predicted sales value for the product: {sales_prediciton}.")
|
| 44 |
+
else:
|
| 45 |
+
st.error("Error in API request. Please check the backend or payload format.")
|
| 46 |
+
|
| 47 |
+
# Section for batch prediction
|
| 48 |
+
st.subheader("Batch Prediction")
|
| 49 |
+
|
| 50 |
+
# File uploader to allow CSV upload for batch prediction
|
| 51 |
+
file = st.file_uploader("Upload CSV file", type=["csv"])
|
| 52 |
+
|
| 53 |
+
if file is not None:
|
| 54 |
+
# When "Predict for Batch" button is clicked, send CSV to backend API
|
| 55 |
+
if st.button("Predict for Batch", type='primary'):
|
| 56 |
+
response = requests.post("https://parthipan00410-salespredictionbackend.hf.space/v1/salesdatabatch", files={"file": file})
|
| 57 |
+
|
| 58 |
+
# Display the batch prediction results if successful
|
| 59 |
+
if response.status_code == 200:
|
| 60 |
+
result = response.json()
|
| 61 |
+
st.header("Batch Prediction Results")
|
| 62 |
+
st.write(result)
|
| 63 |
+
else:
|
| 64 |
+
st.error("Error in API request. Please check the backend or CSV format.")
|
gradient_tuned.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:42b4d70fdf4fd9609e15aec0d5d8426f4a6b1d04b8d958f98de8c2227cfd097a
|
| 3 |
+
size 1650258
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|