Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +9 -13
- app.py +51 -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,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
st.title("🛒 Sales Forecasting App")
|
| 6 |
+
st.subheader("🔮 Online Sales Prediction")
|
| 7 |
+
|
| 8 |
+
# Input fields for product & store data
|
| 9 |
+
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
|
| 10 |
+
Product_Type = st.selectbox("Product Type", [
|
| 11 |
+
"Fruits and Vegetables", "Snack Foods", "Frozen Foods", "Dairy",
|
| 12 |
+
"Household", "Baking Goods", "Canned", "Health and Hygiene",
|
| 13 |
+
"Meat", "Soft Drinks", "Bread", "Breads", "Hard Drinks",
|
| 14 |
+
"Others", "Starchy Foods", "Breakfast", "Seafood"
|
| 15 |
+
])
|
| 16 |
+
Store_Id = st.selectbox("Store Id", ["OUT001", "OUT002", "OUT003", "OUT004"])
|
| 17 |
+
Store_Size = st.selectbox("Store Size", ["Medium", "High", "Low", "Small"])
|
| 18 |
+
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 19 |
+
Store_Type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"])
|
| 20 |
+
|
| 21 |
+
Product_Weight = st.number_input("Product Weight (kg)", min_value=0.0, value=5.0)
|
| 22 |
+
Product_Price = st.number_input("Product Price ($)", min_value=0.0, value=50.0)
|
| 23 |
+
Store_Area = st.number_input("Store Area (sq.ft)", min_value=0.0, value=2000.0)
|
| 24 |
+
|
| 25 |
+
# Prepare input for API
|
| 26 |
+
sales_data = {
|
| 27 |
+
"Product_Sugar_Content": Product_Sugar_Content,
|
| 28 |
+
"Product_Type": Product_Type,
|
| 29 |
+
"Store_Id": Store_Id,
|
| 30 |
+
"Store_Size": Store_Size,
|
| 31 |
+
"Store_Location_City_Type": Store_Location_City_Type,
|
| 32 |
+
"Store_Type": Store_Type,
|
| 33 |
+
"Product_Weight": Product_Weight,
|
| 34 |
+
"Product_Price": Product_Price,
|
| 35 |
+
"Store_Area": Store_Area
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
if st.button("Predict Sales", type='primary'):
|
| 39 |
+
try:
|
| 40 |
+
response = requests.post(
|
| 41 |
+
"https://ankushwaghmare-backend.hf.space/v1/sales_forecast",
|
| 42 |
+
json=sales_data
|
| 43 |
+
)
|
| 44 |
+
if response.status_code == 200:
|
| 45 |
+
result = response.json()
|
| 46 |
+
predictionResult = result["Prediction"]
|
| 47 |
+
st.write(f"ased on the information provided, the prediction is likely to {predictionResult}.")
|
| 48 |
+
else:
|
| 49 |
+
st.error(f"API Error {response.status_code}: {response.text}")
|
| 50 |
+
except Exception as e:
|
| 51 |
+
st.error(f"Request failed: {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
|