Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +9 -13
- app.py +85 -0
- requirements.txt +2 -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,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# App title
|
| 6 |
+
st.title("SuperKart Sales Prediction App")
|
| 7 |
+
|
| 8 |
+
# Input fields for product and store data
|
| 9 |
+
Product_Weight = st.number_input("Product Weight", min_value=0.0, value=12.66)
|
| 10 |
+
|
| 11 |
+
Product_Sugar_Content = st.selectbox(
|
| 12 |
+
"Product Sugar Content",
|
| 13 |
+
["Low Sugar", "Regular", "No Sugar"]
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
Product_Allocated_Area = st.number_input(
|
| 17 |
+
"Product Allocated Area",
|
| 18 |
+
min_value=0.0,
|
| 19 |
+
value=0.05
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
Product_MRP = st.number_input(
|
| 23 |
+
"Product MRP",
|
| 24 |
+
min_value=0.0,
|
| 25 |
+
value=249.81
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
Store_Size = st.selectbox(
|
| 29 |
+
"Store Size",
|
| 30 |
+
["Small", "Medium", "High"]
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
Store_Location_City_Type = st.selectbox(
|
| 34 |
+
"Store Location City Type",
|
| 35 |
+
["Tier 1", "Tier 2", "Tier 3"]
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
Store_Type = st.selectbox(
|
| 39 |
+
"Store Type",
|
| 40 |
+
["Grocery Store", "Supermarket Type1", "Supermarket Type2", "Supermarket Type3"]
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
Product_Id_char = st.selectbox(
|
| 44 |
+
"Product Category (ID Prefix)",
|
| 45 |
+
["FD", "DR", "NC"]
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
Store_Age_Years = st.number_input(
|
| 49 |
+
"Store Age (Years)",
|
| 50 |
+
min_value=0,
|
| 51 |
+
value=15
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
Product_Type_Category = st.selectbox(
|
| 55 |
+
"Product Type Category",
|
| 56 |
+
["Perishables", "Non Perishables"]
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
# Create payload for API
|
| 60 |
+
product_data = {
|
| 61 |
+
"Product_Weight": Product_Weight,
|
| 62 |
+
"Product_Sugar_Content": Product_Sugar_Content,
|
| 63 |
+
"Product_Allocated_Area": Product_Allocated_Area,
|
| 64 |
+
"Product_MRP": Product_MRP,
|
| 65 |
+
"Store_Size": Store_Size,
|
| 66 |
+
"Store_Location_City_Type": Store_Location_City_Type,
|
| 67 |
+
"Store_Type": Store_Type,
|
| 68 |
+
"Product_Id_char": Product_Id_char,
|
| 69 |
+
"Store_Age_Years": Store_Age_Years,
|
| 70 |
+
"Product_Type_Category": Product_Type_Category
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
# Predict button
|
| 74 |
+
if st.button("Predict", type="primary"):
|
| 75 |
+
response = requests.post(
|
| 76 |
+
"https://farukkwansahnyame-SuperkartBackendZ.hf.space/v1/predict",
|
| 77 |
+
json=product_data
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
if response.status_code == 200:
|
| 81 |
+
result = response.json()
|
| 82 |
+
predicted_sales = result["Sales"]
|
| 83 |
+
st.success(f"Predicted Product Store Sales Total: ${predicted_sales:.2f}")
|
| 84 |
+
else:
|
| 85 |
+
st.error("Error in API request")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,2 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
streamlit
|
|
|
|
| 1 |
+
requests==2.32.3
|
| 2 |
+
streamlit==1.45.0
|
|
|