File size: 2,469 Bytes
a73c874
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import gradio as gr
import pickle
import numpy as np

# Load model and scaler
with open("marketing_model.pkl", "rb") as f:
    model = pickle.load(f)

with open("scaler.pkl", "rb") as f:
    scaler = pickle.load(f)


def predict_campaign(
    education, marital_status, income, kidhome, teenhome, recency,
    wines, fruits, meat, fish, sweets, gold,
    deals, web, catalog, store, visits,
    cmp3, cmp4, cmp5, cmp1, cmp2,
    complain, cost_contact, revenue,
    age
):

    total_spending = wines + fruits + meat + fish + sweets + gold

    features = np.array([
        education, marital_status, income, kidhome, teenhome, recency,
        wines, fruits, meat, fish, sweets, gold,
        deals, web, catalog, store, visits,
        cmp3, cmp4, cmp5, cmp1, cmp2,
        complain, cost_contact, revenue,
        age, total_spending
    ]).reshape(1, -1)

    features = scaler.transform(features)

    prediction = model.predict(features)[0]

    if prediction == 1:
        return "✅ Customer will accept the marketing campaign"
    else:
        return "❌ Customer will NOT accept the campaign"


interface = gr.Interface(
    fn=predict_campaign,
    inputs=[
        gr.Number(label="Education"),
        gr.Number(label="Marital Status"),
        gr.Number(label="Income"),
        gr.Number(label="Kidhome"),
        gr.Number(label="Teenhome"),
        gr.Number(label="Recency"),

        gr.Number(label="Wine Spending"),
        gr.Number(label="Fruit Spending"),
        gr.Number(label="Meat Spending"),
        gr.Number(label="Fish Spending"),
        gr.Number(label="Sweet Spending"),
        gr.Number(label="Gold Spending"),

        gr.Number(label="Deals Purchases"),
        gr.Number(label="Web Purchases"),
        gr.Number(label="Catalog Purchases"),
        gr.Number(label="Store Purchases"),
        gr.Number(label="Web Visits Per Month"),

        gr.Number(label="Accepted Campaign 3"),
        gr.Number(label="Accepted Campaign 4"),
        gr.Number(label="Accepted Campaign 5"),
        gr.Number(label="Accepted Campaign 1"),
        gr.Number(label="Accepted Campaign 2"),

        gr.Number(label="Complain"),
        gr.Number(label="Cost Contact"),
        gr.Number(label="Revenue"),
        gr.Number(label="Age"),
    ],
    outputs=gr.Textbox(label="Prediction"),
    title="Sales Analytics & Marketing Automation",
    description="Predict whether a customer will accept a marketing campaign"
)

interface.launch()