akshat22051 commited on
Commit
22833c8
·
verified ·
1 Parent(s): a50a49b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -6,10 +6,8 @@ import joblib
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",
@@ -21,27 +19,28 @@ def predict_excel(file):
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()
 
6
  model = joblib.load("model.joblib")
7
 
8
  def predict_excel(file):
 
9
  df = pd.read_excel(file.name)
10
 
 
11
  required_cols = [
12
  "CustomerID", "Tenure", "PreferredLoginDevice", "CityTier",
13
  "WarehouseToHome", "PreferredPaymentMode", "Gender", "HourSpendOnApp",
 
19
 
20
  missing = [c for c in required_cols if c not in df.columns]
21
  if missing:
22
+ return None, f"❌ Missing columns in Excel: {missing}"
23
 
 
24
  preds = model.predict(df[required_cols])
 
 
25
  df["Prediction"] = preds
26
 
 
27
  out_path = "predicted_output.xlsx"
28
  df.to_excel(out_path, index=False)
29
 
30
+ return out_path, "✅ Successfully generated predictions!"
31
+
32
 
33
  # Gradio UI
34
  demo = gr.Interface(
35
  fn=predict_excel,
36
  inputs=gr.File(label="Upload Excel File (.xlsx)"),
37
+ outputs=[
38
+ gr.File(label="Download Updated Excel With Predictions"),
39
+ gr.Text(label="Status Message")
40
+ ],
41
  title="Excel-Based Customer Churn Predictor",
42
  description="Upload an Excel file to receive a new Excel file with model predictions added."
43
  )
44
 
45
+
46
  demo.launch()