Upload 8 files
Browse files- .gitattributes +1 -0
- Dockerfile +19 -0
- README.md +19 -6
- app.py +67 -0
- assets/Bank Churn.png +3 -0
- models/.gitkeep +0 -0
- requirements.txt +6 -0
- scripts/pipeline.py +31 -0
- style.css +10 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
assets/Bank[[:space:]]Churn.png filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 5 |
+
ENV PYTHONUNBUFFERED=1
|
| 6 |
+
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 7 |
+
ENV GRADIO_SERVER_PORT=7860
|
| 8 |
+
|
| 9 |
+
WORKDIR /app
|
| 10 |
+
|
| 11 |
+
COPY requirements.txt /app/requirements.txt
|
| 12 |
+
|
| 13 |
+
RUN pip install --no-cache-dir --upgrade pip && pip install --no-cache-dir -r requirements.txt
|
| 14 |
+
|
| 15 |
+
COPY . /app
|
| 16 |
+
|
| 17 |
+
EXPOSE 7860
|
| 18 |
+
|
| 19 |
+
CMD ["python","-u","app.py"]
|
README.md
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
-
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
---
|
| 3 |
+
title: Bank Churn Predictor
|
| 4 |
+
emoji: 🏦
|
| 5 |
+
colorFrom: blue
|
| 6 |
+
colorTo: yellow
|
| 7 |
sdk: docker
|
| 8 |
+
app_port: 7860
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# Bank Churn Predictor
|
| 12 |
+
|
| 13 |
+
A stable HuggingFace Docker Space demo.
|
| 14 |
+
|
| 15 |
+
Features
|
| 16 |
+
- Run Pipeline (train model)
|
| 17 |
+
- Execution log viewer
|
| 18 |
+
- Single prediction UI
|
| 19 |
+
- Background image support
|
| 20 |
+
|
| 21 |
+
The pipeline trains a simple model and saves:
|
| 22 |
+
|
| 23 |
+
models/pipeline.joblib
|
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import joblib
|
| 7 |
+
|
| 8 |
+
MODEL_PATH="models/pipeline.joblib"
|
| 9 |
+
|
| 10 |
+
def load_model():
|
| 11 |
+
if os.path.exists(MODEL_PATH):
|
| 12 |
+
return joblib.load(MODEL_PATH)
|
| 13 |
+
return None
|
| 14 |
+
|
| 15 |
+
model=load_model()
|
| 16 |
+
|
| 17 |
+
def predict(age,balance):
|
| 18 |
+
global model
|
| 19 |
+
model=load_model()
|
| 20 |
+
if model is None:
|
| 21 |
+
return "Run pipeline first"
|
| 22 |
+
df=pd.DataFrame([[age,balance]],columns=["Age","Balance"])
|
| 23 |
+
p=model.predict(df)[0]
|
| 24 |
+
return f"Prediction: {p}"
|
| 25 |
+
|
| 26 |
+
def run_pipeline():
|
| 27 |
+
proc=subprocess.Popen(
|
| 28 |
+
["python","scripts/pipeline.py"],
|
| 29 |
+
stdout=subprocess.PIPE,
|
| 30 |
+
stderr=subprocess.STDOUT,
|
| 31 |
+
text=True
|
| 32 |
+
)
|
| 33 |
+
log=""
|
| 34 |
+
for line in proc.stdout:
|
| 35 |
+
log+=line
|
| 36 |
+
yield log
|
| 37 |
+
|
| 38 |
+
def build_ui():
|
| 39 |
+
css=open("style.css").read()
|
| 40 |
+
|
| 41 |
+
with gr.Blocks() as demo:
|
| 42 |
+
|
| 43 |
+
gr.HTML(f"<style>{css}</style>")
|
| 44 |
+
|
| 45 |
+
gr.Markdown("# 🏦 Bank Churn Predictor")
|
| 46 |
+
|
| 47 |
+
with gr.Tab("Pipeline"):
|
| 48 |
+
gr.Markdown("Train model and view execution log")
|
| 49 |
+
btn=gr.Button("Run Pipeline")
|
| 50 |
+
log=gr.Textbox(lines=20,label="Execution Log")
|
| 51 |
+
btn.click(run_pipeline,outputs=log)
|
| 52 |
+
|
| 53 |
+
with gr.Tab("Prediction"):
|
| 54 |
+
age=gr.Number(label="Age")
|
| 55 |
+
balance=gr.Number(label="Balance")
|
| 56 |
+
btn=gr.Button("Predict")
|
| 57 |
+
out=gr.Textbox()
|
| 58 |
+
|
| 59 |
+
btn.click(predict,[age,balance],out)
|
| 60 |
+
|
| 61 |
+
return demo
|
| 62 |
+
|
| 63 |
+
if __name__=="__main__":
|
| 64 |
+
demo=build_ui()
|
| 65 |
+
demo.queue()
|
| 66 |
+
port=int(os.environ.get("PORT",7860))
|
| 67 |
+
demo.launch(server_name="0.0.0.0",server_port=port)
|
assets/Bank Churn.png
ADDED
|
Git LFS Details
|
models/.gitkeep
ADDED
|
File without changes
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0
|
| 2 |
+
pandas
|
| 3 |
+
numpy
|
| 4 |
+
scikit-learn
|
| 5 |
+
joblib
|
| 6 |
+
matplotlib
|
scripts/pipeline.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from sklearn.linear_model import LogisticRegression
|
| 4 |
+
from sklearn.model_selection import train_test_split
|
| 5 |
+
import joblib, os
|
| 6 |
+
|
| 7 |
+
print("===== STEP 1: Load Data =====")
|
| 8 |
+
|
| 9 |
+
data = pd.DataFrame({
|
| 10 |
+
"Age":[25,45,33,52,23,40,60,48],
|
| 11 |
+
"Balance":[1000,5000,2300,8000,1200,4500,9000,3000],
|
| 12 |
+
"Exited":[0,1,0,1,0,1,1,0]
|
| 13 |
+
})
|
| 14 |
+
|
| 15 |
+
print("Dataset ready")
|
| 16 |
+
|
| 17 |
+
print("===== STEP 2: Train Model =====")
|
| 18 |
+
|
| 19 |
+
X=data[["Age","Balance"]]
|
| 20 |
+
y=data["Exited"]
|
| 21 |
+
|
| 22 |
+
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2)
|
| 23 |
+
|
| 24 |
+
model=LogisticRegression()
|
| 25 |
+
model.fit(X_train,y_train)
|
| 26 |
+
|
| 27 |
+
os.makedirs("models",exist_ok=True)
|
| 28 |
+
joblib.dump(model,"models/pipeline.joblib")
|
| 29 |
+
|
| 30 |
+
print("Model saved to models/pipeline.joblib")
|
| 31 |
+
print("Pipeline finished")
|
style.css
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
body {
|
| 3 |
+
background:#0f172a;
|
| 4 |
+
color:white;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
.gradio-container {
|
| 8 |
+
background:transparent;
|
| 9 |
+
}
|
| 10 |
+
|