AkshatGianIIITD
commited on
Commit
·
2226294
1
Parent(s):
aa188b6
Add UI for model
Browse files- app.py +47 -0
- model.joblib +3 -0
- requirements.txt +6 -0
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
# load full pipeline
|
| 6 |
+
model = joblib.load("model.joblib")
|
| 7 |
+
|
| 8 |
+
def predict_excel(file):
|
| 9 |
+
# Read uploaded Excel file
|
| 10 |
+
df = pd.read_excel(file.name)
|
| 11 |
+
|
| 12 |
+
# Check if required columns exist
|
| 13 |
+
required_cols = [
|
| 14 |
+
"CustomerID", "Tenure", "PreferredLoginDevice", "CityTier",
|
| 15 |
+
"WarehouseToHome", "PreferredPaymentMode", "Gender", "HourSpendOnApp",
|
| 16 |
+
"NumberOfDeviceRegistered", "PreferredOrderCat", "SatisfactionScore",
|
| 17 |
+
"MaritalStatus", "NumberOfAddress", "Complain",
|
| 18 |
+
"OrderAmountHikeFromlastYear", "CouponUsed", "OrderCount",
|
| 19 |
+
"DaySinceLastOrder", "CashbackAmount"
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
missing = [c for c in required_cols if c not in df.columns]
|
| 23 |
+
if missing:
|
| 24 |
+
return f"❌ Missing columns in Excel: {missing}"
|
| 25 |
+
|
| 26 |
+
# Predict
|
| 27 |
+
preds = model.predict(df[required_cols])
|
| 28 |
+
|
| 29 |
+
# Add prediction column
|
| 30 |
+
df["Prediction"] = preds
|
| 31 |
+
|
| 32 |
+
# Save to new Excel file
|
| 33 |
+
out_path = "predicted_output.xlsx"
|
| 34 |
+
df.to_excel(out_path, index=False)
|
| 35 |
+
|
| 36 |
+
return out_path # Gradio will let user download it
|
| 37 |
+
|
| 38 |
+
# Gradio UI
|
| 39 |
+
demo = gr.Interface(
|
| 40 |
+
fn=predict_excel,
|
| 41 |
+
inputs=gr.File(label="Upload Excel File (.xlsx)"),
|
| 42 |
+
outputs=gr.File(label="Download Updated Excel With Predictions"),
|
| 43 |
+
title="Excel-Based Customer Churn Predictor",
|
| 44 |
+
description="Upload an Excel file to receive a new Excel file with model predictions added."
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
demo.launch()
|
model.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1793d656c56c9a40407d5dcdcc5bc5b286eed5ff5ed212e14d0e0736ed5b85a7
|
| 3 |
+
size 507659
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pandas
|
| 3 |
+
numpy
|
| 4 |
+
scikit-learn
|
| 5 |
+
joblib
|
| 6 |
+
openpyxl
|