Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +16 -0
- app.py +85 -0
- requirements.txt +3 -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 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,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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("Sales Prediction")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Online Prediction")
|
| 10 |
+
|
| 11 |
+
# Collect user input for product and store features
|
| 12 |
+
Product_Weight = st.number_input("Product Weight", min_value=0.0, value=15.0)
|
| 13 |
+
Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.0, value=200.0)
|
| 14 |
+
Product_MRP = st.number_input("Product MRP", min_value=0.0, value=100.0)
|
| 15 |
+
Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1900, max_value=2024, value=2000)
|
| 16 |
+
Product_Sugar_Content_No_Sugar = st.selectbox("Product Sugar Content No Sugar", [0, 1])
|
| 17 |
+
Product_Sugar_Content_Regular = st.selectbox("Product Sugar Content Regular", [0, 1])
|
| 18 |
+
Product_Sugar_Content_reg = st.selectbox("Product Sugar Content reg", [0, 1])
|
| 19 |
+
Product_Type_Breads = st.selectbox("Product Type Breads", [0, 1])
|
| 20 |
+
Product_Type_Breakfast = st.selectbox("Product Type Breakfast", [0, 1])
|
| 21 |
+
Product_Type_Canned = st.selectbox("Product Type Canned", [0, 1])
|
| 22 |
+
Product_Type_Dairy = st.selectbox("Product Type Dairy", [0, 1])
|
| 23 |
+
Product_Type_Frozen_Foods = st.selectbox("Product Type Frozen Foods", [0, 1])
|
| 24 |
+
Product_Type_Fruits_and_Vegetables = st.selectbox("Product Type Fruits and Vegetables", [0, 1])
|
| 25 |
+
Product_Type_Hard_Drinks = st.selectbox("Product Type Hard Drinks", [0, 1])
|
| 26 |
+
Product_Type_Health_and_Hygiene = st.selectbox("Product Type Health and Hygiene", [0, 1])
|
| 27 |
+
Product_Type_Household = st.selectbox("Product Type Household", [0, 1])
|
| 28 |
+
Product_Type_Meat = st.selectbox("Product Type Meat", [0, 1])
|
| 29 |
+
Product_Type_Others = st.selectbox("Product Type Others", [0, 1])
|
| 30 |
+
Product_Type_Seafood = st.selectbox("Product Type Seafood", [0, 1])
|
| 31 |
+
Product_Type_Snack_Foods = st.selectbox("Product Type Snack Foods", [0, 1])
|
| 32 |
+
Product_Type_Soft_Drinks = st.selectbox("Product Type Soft Drinks", [0, 1])
|
| 33 |
+
Product_Type_Starchy_Foods = st.selectbox("Product Type Starchy Foods", [0, 1])
|
| 34 |
+
Store_Size_Medium = st.selectbox("Store Size Medium", [0, 1])
|
| 35 |
+
Store_Size_Small = st.selectbox("Store Size Small", [0, 1])
|
| 36 |
+
Store_Location_City_Type_Tier_2 = st.selectbox("Store Location City Type Tier 2", [0, 1])
|
| 37 |
+
Store_Location_City_Type_Tier_3 = st.selectbox("Store Location City Type Tier 3", [0, 1])
|
| 38 |
+
Store_Type_Food_Mart = st.selectbox("Store Type Food Mart", [0, 1])
|
| 39 |
+
Store_Type_Supermarket_Type1 = st.selectbox("Store Type Supermarket Type1", [0, 1])
|
| 40 |
+
Store_Type_Supermarket_Type2 = st.selectbox("Store Type Supermarket Type2", [0, 1])
|
| 41 |
+
|
| 42 |
+
# Convert user input into a DataFrame
|
| 43 |
+
input_data = pd.DataFrame([{
|
| 44 |
+
'Product_Weight': Product_Weight,
|
| 45 |
+
'Product_Allocated_Area': Product_Allocated_Area,
|
| 46 |
+
'Product_MRP': Product_MRP,
|
| 47 |
+
'Store_Establishment_Year': Store_Establishment_Year,
|
| 48 |
+
'Product_Sugar_Content_No Sugar': Product_Sugar_Content_No_Sugar,
|
| 49 |
+
'Product_Sugar_Content_Regular': Product_Sugar_Content_Regular,
|
| 50 |
+
'Product_Sugar_Content_reg': Product_Sugar_Content_reg,
|
| 51 |
+
'Product_Type_Breads': Product_Type_Breads,
|
| 52 |
+
'Product_Type_Breakfast': Product_Type_Breakfast,
|
| 53 |
+
'Product_Type_Canned': Product_Type_Canned,
|
| 54 |
+
'Product_Type_Dairy': Product_Type_Dairy,
|
| 55 |
+
'Product_Type_Frozen Foods': Product_Type_Frozen_Foods,
|
| 56 |
+
'Product_Type_Fruits and Vegetables': Product_Type_Fruits_and_Vegetables,
|
| 57 |
+
'Product_Type_Hard Drinks': Product_Type_Hard_Drinks,
|
| 58 |
+
'Product_Type_Health and Hygiene': Product_Type_Health_and_Hygiene,
|
| 59 |
+
'Product_Type_Household': Product_Type_Household,
|
| 60 |
+
'Product_Type_Meat': Product_Type_Meat,
|
| 61 |
+
'Product_Type_Others': Product_Type_Others,
|
| 62 |
+
'Product_Type_Seafood': Product_Type_Seafood,
|
| 63 |
+
'Product_Type_Snack Foods': Product_Type_Snack_Foods,
|
| 64 |
+
'Product_Type_Soft Drinks': Product_Type_Soft_Drinks,
|
| 65 |
+
'Product_Type_Starchy Foods': Product_Type_Starchy_Foods,
|
| 66 |
+
'Store_Size_Medium': Store_Size_Medium,
|
| 67 |
+
'Store_Size_Small': Store_Size_Small,
|
| 68 |
+
'Store_Location_City_Type_Tier 2': Store_Location_City_Type_Tier_2,
|
| 69 |
+
'Store_Location_City_Type_Tier 3': Store_Location_City_Type_Tier_3,
|
| 70 |
+
'Store_Type_Food Mart': Store_Type_Food_Mart,
|
| 71 |
+
'Store_Type_Supermarket Type1': Store_Type_Supermarket_Type1,
|
| 72 |
+
'Store_Type_Supermarket Type2': Store_Type_Supermarket_Type2
|
| 73 |
+
}])
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
#https://huggingface.co/spaces/nlauchande/ForecastBackend/v1/predict
|
| 77 |
+
|
| 78 |
+
# Make prediction when the "Predict" button is clicked
|
| 79 |
+
if st.button("Predict"):
|
| 80 |
+
response = requests.post("https://nlauchande-nlauchande/ForecastBackend2.hf.space/v1/predict", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 81 |
+
if response.status_code == 200:
|
| 82 |
+
prediction = response.json()['Predicted Sales']
|
| 83 |
+
st.success(f"Predicted Sales: {prediction}")
|
| 84 |
+
else:
|
| 85 |
+
st.error("Error making prediction.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|
| 3 |
+
streamlit==1.43.2
|