Upload folder using huggingface_hub
Browse files- Dockerfile +9 -13
- app.py +71 -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,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 Product Revenue Prediction")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Online Prediction")
|
| 10 |
+
|
| 11 |
+
# Collect user input for property features
|
| 12 |
+
Product_Id = st.text_input("Product ID (e.g., FD123)")
|
| 13 |
+
Product_weight = st.number_input("Product Weight (in grams)", min_value=0.0, step=0.1)
|
| 14 |
+
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
|
| 15 |
+
Product_Allocated_Area = st.number_input("Product Allocated Area (Ratio)", min_value=0.0, max_value=1.0, step=0.01)
|
| 16 |
+
Product_Type = st.selectbox(
|
| 17 |
+
"Product Type",
|
| 18 |
+
[
|
| 19 |
+
"Meat", "Snack Foods", "Hard Drinks", "Dairy", "Canned", "Soft Drinks",
|
| 20 |
+
"Health and Hygiene", "Baking Goods", "Bread", "Breakfast", "Frozen Foods",
|
| 21 |
+
"Fruits and Vegetables", "Household", "Seafood", "Starchy Foods", "Others"
|
| 22 |
+
]
|
| 23 |
+
)
|
| 24 |
+
Product_MRP = st.number_input("Product MRP (Maximum Retail Price)", min_value=0.0, step=0.5)
|
| 25 |
+
Store_Id = st.text_input("Store ID (e.g., ST001)")
|
| 26 |
+
Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, step=1, value=2000)
|
| 27 |
+
Store_Size = st.selectbox("Store Size", ["High", "Medium", "Low"])
|
| 28 |
+
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 29 |
+
Store_Type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type 1", "Supermarket Type 2", "Food Mart"])
|
| 30 |
+
|
| 31 |
+
# Convert user input into a DataFrame
|
| 32 |
+
input_data = pd.DataFrame([{
|
| 33 |
+
'Product_Id': Product_Id,
|
| 34 |
+
'Product_Weight': Product_Weight,
|
| 35 |
+
'Product_Sugar_Content': Product_Sugar_Content,
|
| 36 |
+
'Product_Allocated_Area': Product_Allocated_Area,
|
| 37 |
+
'Product_Type': Product_Type,
|
| 38 |
+
'Product_MRP': Product_MRP,
|
| 39 |
+
'Store_Id': Store_Id,
|
| 40 |
+
'Store_Establishment_Year': Store_Establishment_Year,
|
| 41 |
+
'Store_Size': Store_Size,
|
| 42 |
+
'Store_Location_City_Type': Store_Location_City_Type,
|
| 43 |
+
'Store_Type': Store_Type
|
| 44 |
+
}])
|
| 45 |
+
|
| 46 |
+
# Make prediction when the "Predict" button is clicked
|
| 47 |
+
if st.button("Predict"):
|
| 48 |
+
response = requests.post("https://Anu159/SuperKartSalesForecastPredictionBackend.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 49 |
+
if response.status_code == 200:
|
| 50 |
+
prediction = response.json()['Predicted Price (in dollars)']
|
| 51 |
+
st.success(f"Predicted Product Revenue (in dollars): {prediction}")
|
| 52 |
+
else:
|
| 53 |
+
st.error("Error making prediction.")
|
| 54 |
+
|
| 55 |
+
# Section for batch prediction
|
| 56 |
+
st.subheader("Batch Prediction")
|
| 57 |
+
|
| 58 |
+
# Allow users to upload a CSV file for batch prediction
|
| 59 |
+
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
| 60 |
+
|
| 61 |
+
# Make batch prediction when the "Predict Batch" button is clicked
|
| 62 |
+
if uploaded_file is not None:
|
| 63 |
+
if st.button("Predict Batch"):
|
| 64 |
+
response = requests.post("https://Anu159/SuperKartSalesForecastPredictionBackend.hf.space/v1/salesbatch", files={"file": uploaded_file}) # Send file to Flask API
|
| 65 |
+
if response.status_code == 200:
|
| 66 |
+
predictions = response.json()
|
| 67 |
+
st.success("Batch predictions completed!")
|
| 68 |
+
st.write(predictions) # Display the predictions
|
| 69 |
+
else:
|
| 70 |
+
st.error("Error making batch prediction.")
|
| 71 |
+
|
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
|