Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +9 -13
- app.py +63 -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,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
st.title("Ftontend Prediction")
|
| 6 |
+
|
| 7 |
+
# Batch Prediction
|
| 8 |
+
st.subheader("Online Prediction")
|
| 9 |
+
|
| 10 |
+
# Input fields for data entry (default values = median from your description)
|
| 11 |
+
ID = st.number_input("Customer ID", min_value=1, max_value=5000, value=2500)
|
| 12 |
+
Age = st.number_input("Age", min_value=18, max_value=100, value=45)
|
| 13 |
+
Experience = st.number_input("Experience (Years)", min_value=-5, max_value=50, value=20)
|
| 14 |
+
Income = st.number_input("Annual Income (in $000)", min_value=0, max_value=300, value=64)
|
| 15 |
+
ZIPCode = st.number_input("ZIP Code", min_value=90000, max_value=99999, value=93437)
|
| 16 |
+
Family = st.selectbox("Family Members", [1, 2, 3, 4], index=1)
|
| 17 |
+
CCAvg = st.number_input("Credit Card Avg Monthly Spend", min_value=0.0, max_value=10.0, value=1.5)
|
| 18 |
+
Education = st.selectbox("Education Level", [1, 2, 3], index=1)
|
| 19 |
+
Mortgage = st.number_input("Mortgage Amount", min_value=0, max_value=1000, value=0)
|
| 20 |
+
Securities_Account = st.selectbox("Has Securities Account?", [0, 1], index=0)
|
| 21 |
+
CD_Account = st.selectbox("Has CD Account?", [0, 1], index=0)
|
| 22 |
+
Online = st.selectbox("Uses Online Banking?", [0, 1], index=1)
|
| 23 |
+
CreditCard = st.selectbox("Has Credit Card?", [0, 1], index=0)
|
| 24 |
+
|
| 25 |
+
# Dictionary for model input
|
| 26 |
+
user_input_data = {
|
| 27 |
+
'ID': ID,
|
| 28 |
+
'Age': Age,
|
| 29 |
+
'Experience': Experience,
|
| 30 |
+
'Income': Income,
|
| 31 |
+
'ZIPCode': ZIPCode,
|
| 32 |
+
'Family': Family,
|
| 33 |
+
'CCAvg': CCAvg,
|
| 34 |
+
'Education': Education,
|
| 35 |
+
'Mortgage': Mortgage,
|
| 36 |
+
'Securities_Account': Securities_Account,
|
| 37 |
+
'CD_Account': CD_Account,
|
| 38 |
+
'Online': Online,
|
| 39 |
+
'CreditCard': CreditCard
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
if st.button("Predict", type='primary'):
|
| 43 |
+
response = requests.post("https://kjdeka-test-backend.hf.space/v1/dijakbn", json=user_input_data) # enter user name and backend space name before running the cell
|
| 44 |
+
if response.status_code == 200:
|
| 45 |
+
result = response.json()
|
| 46 |
+
frontend_prediction = result["Prediction"] # Extract only the value
|
| 47 |
+
st.write(f"Prediction is {frontend_prediction}.")
|
| 48 |
+
else:
|
| 49 |
+
st.error("Error in API request")
|
| 50 |
+
|
| 51 |
+
# Batch Prediction
|
| 52 |
+
st.subheader("Batch Prediction")
|
| 53 |
+
|
| 54 |
+
file = st.file_uploader("Upload CSV file", type=["csv"])
|
| 55 |
+
if file is not None:
|
| 56 |
+
if st.button("Predict for Batch", type='primary'):
|
| 57 |
+
response = requests.post("https://kjdeka-test-backend.hf.space/v1/dijakbnbatch", files={"file": file}) # enter user name and backend space name before running the cell
|
| 58 |
+
if response.status_code == 200:
|
| 59 |
+
result = response.json()
|
| 60 |
+
st.header("Batch Prediction Results")
|
| 61 |
+
st.write(result)
|
| 62 |
+
else:
|
| 63 |
+
st.error("Error in API request")
|
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
|