File size: 1,879 Bytes
b33b9dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import pandas as pd
import gradio as gr
import joblib as jp




model=jp.load('model.pkl')
std = jp.load("std_col.pkl")
le = jp.load("le_col.pkl")

le_col=['gender','education','region','purchase_frequency','product_category']
std_col=['age','income','purchase_amount']

def Customer_Predction_Model(ag,gender,income,edu,reg,loy,pr,pu,prod,prom,sts):
    try:
        input_data=pd.DataFrame({   
        'age':[ag],
        'gender':[gender],
        'income':[income],
        'education':[edu],
        'region':[reg],
        'loyalty_status':[loy],
        'purchase_frequency':[pr],
        'purchase_amount':[pu],
        'product_category':[prod],
        'promotion_usage':[prom],
        'satisfaction_score':[sts]
        })
        for col in le_col:
            input_data[col]=le[col].transform(input_data[col])
        input_data[std_col]=std.transform(input_data[std_col])
        prediction=model.predict(input_data)
        if prediction[0]==0:
            return 'No'
        else:
            return 'Yes'
            
    except Exception as e:
        return str(e)
gr.Interface(
    fn=Customer_Predction_Model,
    inputs=[
    gr.Number(label='age'),
    gr.Dropdown(['Male','Female'],label='gender'),
    gr.Number(label='income'),
    gr.Dropdown(['College','Bachelor','HighSchool','Masters'],label='education'),
    gr.Dropdown(['East','West','South','North'],label='region'),
    gr.Number(label='loyalty_status'),
    gr.Dropdown(['rare','occasional','frequent'],label='purchase_frequency'),
    gr.Number(label='purchase_amount'),
    gr.Dropdown(['Electronics','Clothing','Books','Food','Health','Home','Beauty'],label='product_category'),
    gr.Number(label='promotion_usage'),
    gr.Number(label='satisfaction_score')
    
],
    outputs=gr.Textbox(label='Prediction'),
    title='Customer Purchase Anticipation Prediction Model'

).launch()