Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import joblib
|
4 |
+
|
5 |
+
# Load the trained pipeline
|
6 |
+
pipeline_path = 'src/Asset/ML/randomforest_pipeline.pkl'
|
7 |
+
model_pipeline = joblib.load(pipeline_path)
|
8 |
+
|
9 |
+
# Define your prediction function
|
10 |
+
def deposit_subscription_prediction(age, job, marital, education, default, housing, loan, contact, month,
|
11 |
+
day_of_week, duration, campaign, pdays, previous, poutcome, emp_var_rate, cons_price_idx,
|
12 |
+
cons_conf_idx, euribor3m, nr_employed):
|
13 |
+
# Create a DataFrame with the provided inputs
|
14 |
+
prediction_data = pd.DataFrame({
|
15 |
+
'age': [age],
|
16 |
+
'job': [job],
|
17 |
+
'marital': [marital],
|
18 |
+
'education': [education],
|
19 |
+
'default': [default],
|
20 |
+
'housing': [housing],
|
21 |
+
'loan': [loan],
|
22 |
+
'contact': [contact],
|
23 |
+
'month': [month],
|
24 |
+
'day_of_week': [day_of_week],
|
25 |
+
'duration': [duration],
|
26 |
+
'campaign': [campaign],
|
27 |
+
'pdays': [pdays],
|
28 |
+
'previous': [previous],
|
29 |
+
'poutcome': [poutcome],
|
30 |
+
'emp_var_rate': [emp_var_rate],
|
31 |
+
'cons_price_idx': [cons_price_idx],
|
32 |
+
'cons_conf_idx': [cons_conf_idx],
|
33 |
+
'euribor3m': [euribor3m],
|
34 |
+
'nr_employed': [nr_employed]
|
35 |
+
})
|
36 |
+
|
37 |
+
# Make predictions using the pipeline
|
38 |
+
prediction = model_pipeline.predict(prediction_data)[0]
|
39 |
+
|
40 |
+
# Map the prediction to a label
|
41 |
+
prediction_label = 'Subscribed to Deposit' if prediction == 1 else 'Not Subscribed to Deposit'
|
42 |
+
|
43 |
+
return prediction_label
|
44 |
+
|
45 |
+
# Define input components for the Gradio interface
|
46 |
+
input_components = [
|
47 |
+
gr.Number(label='Age: Enter the age of the customer.', minimum=17, maximum=98),
|
48 |
+
gr.Dropdown(choices=['blue-collar', 'entrepreneur', 'housemaid', 'management', 'retired', 'self-employed', 'services', 'student', 'technician', 'unemployed', 'admin.', 'unknown'], label='Job: Select the job type of the customer.'),
|
49 |
+
gr.Dropdown(choices=['single', 'married', 'divorced'], label='Marital: Select the marital status of the customer.'),
|
50 |
+
gr.Dropdown(choices=['basic.4y', 'basic.6y', 'basic.9y', 'high.school', 'illiterate', 'professional.course', 'university.degree', 'unknown'], label='Education: Select the education level of the customer.'),
|
51 |
+
gr.Dropdown(choices=['no', 'yes'], label='Default: Select if the customer has credit in default.'),
|
52 |
+
gr.Dropdown(choices=['no', 'yes'], label='Housing: Select if the customer has a housing loan.'),
|
53 |
+
gr.Dropdown(choices=['no', 'yes'], label='Loan: Select if the customer has a personal loan.'),
|
54 |
+
gr.Dropdown(choices=['cellular', 'telephone', 'unknown'], label='Contact: Select the communication type used for contact.'),
|
55 |
+
gr.Dropdown(choices=['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'], label='Month: Select the last contact month of the customer.'),
|
56 |
+
gr.Dropdown(choices=['mon', 'tue', 'wed', 'thu', 'fri'], label='Day of Week: Select the last contact day of the week.'),
|
57 |
+
gr.Number(label='Duration: Enter the duration of the last contact in seconds.', minimum=0, maximum=4918),
|
58 |
+
gr.Number(label='Campaign: Enter the number of contacts performed during the campaign.', minimum=1, maximum=56),
|
59 |
+
gr.Number(label='Pdays: Enter the number of days since the client was last contacted.', minimum=-1, maximum=999),
|
60 |
+
gr.Number(label='Previous: Enter the number of contacts performed before this campaign.', minimum=0, maximum=7),
|
61 |
+
gr.Dropdown(choices=['failure', 'nonexistent', 'success', 'unknown'], label='Poutcome: Select the outcome of the previous marketing campaign.'),
|
62 |
+
gr.Number(label='Employment Variation Rate: Enter the employment variation rate.', minimum=-3.40, maximum=1.40),
|
63 |
+
gr.Number(label='Consumer Price Index: Enter the consumer price index.', minimum=92.0, maximum=95.0),
|
64 |
+
gr.Number(label='Consumer Confidence Index: Enter the consumer confidence index.', minimum=-51.0, maximum=-27.0),
|
65 |
+
gr.Number(label='Euribor 3 Month Rate: Enter the Euribor 3 month rate.', minimum=0.63, maximum=5.0),
|
66 |
+
gr.Number(label='Number of Employees: Enter the number of employees.', minimum=4965, maximum=5228)
|
67 |
+
]
|
68 |
+
|
69 |
+
# Create and launch the Gradio interface
|
70 |
+
iface = gr.Interface(
|
71 |
+
fn=deposit_subscription_prediction,
|
72 |
+
inputs=input_components,
|
73 |
+
outputs="text",
|
74 |
+
title="Deposit Subscription Prediction",
|
75 |
+
description="Predict whether a customer will subscribe to a term deposit using machine learning. Enter customer information to get a prediction.",
|
76 |
+
live=False
|
77 |
+
)
|
78 |
+
|
79 |
+
iface.launch()
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
|
90 |
+
|
91 |
+
|
92 |
+
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
|
106 |
+
|