Spaces:
Running
Running
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pickle
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load model and scaler
|
| 6 |
+
with open("marketing_model.pkl", "rb") as f:
|
| 7 |
+
model = pickle.load(f)
|
| 8 |
+
|
| 9 |
+
with open("scaler.pkl", "rb") as f:
|
| 10 |
+
scaler = pickle.load(f)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def predict_campaign(
|
| 14 |
+
education, marital_status, income, kidhome, teenhome, recency,
|
| 15 |
+
wines, fruits, meat, fish, sweets, gold,
|
| 16 |
+
deals, web, catalog, store, visits,
|
| 17 |
+
cmp3, cmp4, cmp5, cmp1, cmp2,
|
| 18 |
+
complain, cost_contact, revenue,
|
| 19 |
+
age
|
| 20 |
+
):
|
| 21 |
+
|
| 22 |
+
total_spending = wines + fruits + meat + fish + sweets + gold
|
| 23 |
+
|
| 24 |
+
features = np.array([
|
| 25 |
+
education, marital_status, income, kidhome, teenhome, recency,
|
| 26 |
+
wines, fruits, meat, fish, sweets, gold,
|
| 27 |
+
deals, web, catalog, store, visits,
|
| 28 |
+
cmp3, cmp4, cmp5, cmp1, cmp2,
|
| 29 |
+
complain, cost_contact, revenue,
|
| 30 |
+
age, total_spending
|
| 31 |
+
]).reshape(1, -1)
|
| 32 |
+
|
| 33 |
+
features = scaler.transform(features)
|
| 34 |
+
|
| 35 |
+
prediction = model.predict(features)[0]
|
| 36 |
+
|
| 37 |
+
if prediction == 1:
|
| 38 |
+
return "✅ Customer will accept the marketing campaign"
|
| 39 |
+
else:
|
| 40 |
+
return "❌ Customer will NOT accept the campaign"
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
interface = gr.Interface(
|
| 44 |
+
fn=predict_campaign,
|
| 45 |
+
inputs=[
|
| 46 |
+
gr.Number(label="Education"),
|
| 47 |
+
gr.Number(label="Marital Status"),
|
| 48 |
+
gr.Number(label="Income"),
|
| 49 |
+
gr.Number(label="Kidhome"),
|
| 50 |
+
gr.Number(label="Teenhome"),
|
| 51 |
+
gr.Number(label="Recency"),
|
| 52 |
+
|
| 53 |
+
gr.Number(label="Wine Spending"),
|
| 54 |
+
gr.Number(label="Fruit Spending"),
|
| 55 |
+
gr.Number(label="Meat Spending"),
|
| 56 |
+
gr.Number(label="Fish Spending"),
|
| 57 |
+
gr.Number(label="Sweet Spending"),
|
| 58 |
+
gr.Number(label="Gold Spending"),
|
| 59 |
+
|
| 60 |
+
gr.Number(label="Deals Purchases"),
|
| 61 |
+
gr.Number(label="Web Purchases"),
|
| 62 |
+
gr.Number(label="Catalog Purchases"),
|
| 63 |
+
gr.Number(label="Store Purchases"),
|
| 64 |
+
gr.Number(label="Web Visits Per Month"),
|
| 65 |
+
|
| 66 |
+
gr.Number(label="Accepted Campaign 3"),
|
| 67 |
+
gr.Number(label="Accepted Campaign 4"),
|
| 68 |
+
gr.Number(label="Accepted Campaign 5"),
|
| 69 |
+
gr.Number(label="Accepted Campaign 1"),
|
| 70 |
+
gr.Number(label="Accepted Campaign 2"),
|
| 71 |
+
|
| 72 |
+
gr.Number(label="Complain"),
|
| 73 |
+
gr.Number(label="Cost Contact"),
|
| 74 |
+
gr.Number(label="Revenue"),
|
| 75 |
+
gr.Number(label="Age"),
|
| 76 |
+
],
|
| 77 |
+
outputs=gr.Textbox(label="Prediction"),
|
| 78 |
+
title="Sales Analytics & Marketing Automation",
|
| 79 |
+
description="Predict whether a customer will accept a marketing campaign"
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
interface.launch()
|