File size: 1,382 Bytes
f6b7147
 
 
 
 
 
 
 
5763904
f6b7147
 
 
 
5ffebd7
f6b7147
 
 
 
 
 
 
22833c8
f6b7147
 
 
 
 
 
 
22833c8
 
f6b7147
 
 
 
 
22833c8
 
 
 
f6b7147
 
 
 
22833c8
f6b7147
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import gradio as gr
import pandas as pd
import joblib

# load full pipeline
model = joblib.load("model.joblib")

def predict_excel(file):
    df = pd.read_excel(file.name, sheet_name="E Comm")

    required_cols = [
        "CustomerID", "Tenure", "PreferredLoginDevice", "CityTier",
        "WarehouseToHome", "PreferredPaymentMode", "Gender", "HourSpendOnApp",
        "NumberOfDeviceRegistered", "PreferedOrderCat", "SatisfactionScore",
        "MaritalStatus", "NumberOfAddress", "Complain",
        "OrderAmountHikeFromlastYear", "CouponUsed", "OrderCount",
        "DaySinceLastOrder", "CashbackAmount"
    ]

    missing = [c for c in required_cols if c not in df.columns]
    if missing:
        return None, f"❌ Missing columns in Excel: {missing}"

    preds = model.predict(df[required_cols])
    df["Prediction"] = preds

    out_path = "predicted_output.xlsx"
    df.to_excel(out_path, index=False)

    return out_path, "✅ Successfully generated predictions!"


# Gradio UI
demo = gr.Interface(
    fn=predict_excel,
    inputs=gr.File(label="Upload Excel File (.xlsx)"),
    outputs=[
        gr.File(label="Download Updated Excel With Predictions"),
        gr.Text(label="Status Message")
    ],
    title="Excel-Based Customer Churn Predictor",
    description="Upload an Excel file to receive a new Excel file with model predictions added."
)


demo.launch()