Download app.py from akshat22051/HCL_hackathon_model: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/akshat22051/HCL_hackathon_model/resolve/main/app.py
- Command line
-
hf download hf://akshat22051/HCL_hackathon_model/app.py
-
curl -L -o app.py https://huggingface.co/akshat22051/HCL_hackathon_model/resolve/main/app.py
1.43 kB
| import gradio as gr | |
| import pandas as pd | |
| import joblib | |
| # load full pipeline | |
| model = joblib.load("model.joblib") | |
| def predict_excel(file): | |
| # Read uploaded Excel file | |
| df = pd.read_excel(file.name) | |
| # Check if required columns exist | |
| required_cols = [ | |
| "CustomerID", "Tenure", "PreferredLoginDevice", "CityTier", | |
| "WarehouseToHome", "PreferredPaymentMode", "Gender", "HourSpendOnApp", | |
| "NumberOfDeviceRegistered", "PreferredOrderCat", "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 f"❌ Missing columns in Excel: {missing}" | |
| # Predict | |
| preds = model.predict(df[required_cols]) | |
| # Add prediction column | |
| df["Prediction"] = preds | |
| # Save to new Excel file | |
| out_path = "predicted_output.xlsx" | |
| df.to_excel(out_path, index=False) | |
| return out_path # Gradio will let user download it | |
| # 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"), | |
| title="Excel-Based Customer Churn Predictor", | |
| description="Upload an Excel file to receive a new Excel file with model predictions added." | |
| ) | |
| demo.launch() | |