Upload folder using huggingface_hub
Browse files- Dockerfile +16 -0
- app.py +56 -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,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Streamlit UI for Customer Churn Prediction
|
| 6 |
+
st.title("Product Sales Prediction App")
|
| 7 |
+
st.write("This tool predicts production sales prediction. Enter the required information below.")
|
| 8 |
+
|
| 9 |
+
# Collect user input based on dataset columns
|
| 10 |
+
weight = st.number_input("Product Weight", min_value=1, max_value=99999999)
|
| 11 |
+
sugarcontent = st.selectbox("Product Sugar Content", ["Low Sugar", "No Sugar", "Regular Sugar", "reg"])
|
| 12 |
+
area = st.number_input("Product allocated area", min_value=1, max_value=9999999)
|
| 13 |
+
producttype = st.selectbox("Product type", ["Frozen Foods", "Dairy", "Canned", "Baking Goods", "Health and Hygiene", "Snack Foods", "Meat", "Household", "Hard Drinks", "Fruits and Vegetables",
|
| 14 |
+
"Breads", "Others", "Starchy Foods", Seafood"])
|
| 15 |
+
productmrp = st.number_input("Product MRP", min_val=1, max_value=9999999)
|
| 16 |
+
year = st.number_input("Store establishment year", min_value=1985, max_val=2024)
|
| 17 |
+
storesize = st.selectbox("store size", ["Small", "Medium", "High"])
|
| 18 |
+
citytype = st.number_input("City type", ["Tier1", "Tier2", "Tier3"])
|
| 19 |
+
storetype = st.selectbox("store type", ["Supermarket Type1", "Supermarket Type2", "Food Mart", "Departmental Store"])
|
| 20 |
+
|
| 21 |
+
# Convert categorical inputs to match model training
|
| 22 |
+
customer_data = {
|
| 23 |
+
'Product Weight': weight
|
| 24 |
+
'Product Sugar Content':sugarcontent,
|
| 25 |
+
'Product allocated area': area,
|
| 26 |
+
'Product Type': producttype,
|
| 27 |
+
'Product MRP': productmrp,
|
| 28 |
+
'Store establishment year': year,
|
| 29 |
+
'store size': storesize,
|
| 30 |
+
'City type': citytype,
|
| 31 |
+
'store type': storetype,
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
if st.button("Predict", type='primary'):
|
| 36 |
+
response = requests.post("https://sp1505-frontend.hf.space/v1/customer", json=customer_data) # enter user name and space name before running the cell
|
| 37 |
+
if response.status_code == 200:
|
| 38 |
+
result = response.json()
|
| 39 |
+
churn_prediction = result["Prediction"] # Extract only the value
|
| 40 |
+
st.write(f"Based on the information provided, the customer with ID {CustomerID} is likely to {churn_prediction}.")
|
| 41 |
+
else:
|
| 42 |
+
st.error("Error in API request")
|
| 43 |
+
|
| 44 |
+
# Batch Prediction
|
| 45 |
+
st.subheader("Batch Prediction")
|
| 46 |
+
|
| 47 |
+
file = st.file_uploader("Upload CSV file", type=["csv"])
|
| 48 |
+
if file is not None:
|
| 49 |
+
if st.button("Predict for Batch", type='primary'):
|
| 50 |
+
response = requests.post("https://sp1505-frontend.hf.space/v1/customerbatch", files={"file": file}) # enter user name and space name before running the cell
|
| 51 |
+
if response.status_code == 200:
|
| 52 |
+
result = response.json()
|
| 53 |
+
st.header("Batch Prediction Results")
|
| 54 |
+
st.write(result)
|
| 55 |
+
else:
|
| 56 |
+
st.error("Error in API request")
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|
| 3 |
+
streamlit==1.43.2
|