Awudu-Jamal1 commited on
Commit
fb3a589
1 Parent(s): 663a1bf
Files changed (1) hide show
  1. app.py +89 -0
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import pickle
4
+
5
+ xtrain= pd.read_csv('Xtrains.csv')
6
+ ytrain=pd.read_csv('Ytrains.csv')
7
+
8
+ # Loading Models
9
+ with open("model.pkl", "rb") as f:
10
+ clf = pickle.load(f)
11
+
12
+ clf.fit(xtrain, ytrain.values.ravel())
13
+
14
+ tenure_labels = {
15
+ 0: "3-6 months",
16
+ 1: "6-9 months",
17
+ 2: "9-12 months",
18
+ 3: "12-15 months",
19
+ 4: "15-18 months",
20
+ 5: "18-21 months",
21
+ 6: "21-24 months",
22
+ 7: "> 24 months"
23
+ }
24
+
25
+ # Reverse the mapping for predictions
26
+ tenure_values = {v: k for k, v in tenure_labels.items()}
27
+
28
+ def predict(tenure, montant, freq_rech, revenue, arpu, freq, data_vol, on_net, orange, tigo, freq_top_pack, regularity):
29
+
30
+ tenure_value = tenure_values[tenure]
31
+
32
+
33
+
34
+ input_df = pd.DataFrame({
35
+ 'TENURE': [tenure_value],
36
+ 'MONTANT': [montant],
37
+ 'FREQUENCE_RECH': [freq_rech],
38
+ 'REVENUE': [revenue],
39
+ 'ARPU_SEGMENT': [arpu],
40
+ 'FREQUENCE': [freq],
41
+ 'DATA_VOLUME': [data_vol],
42
+ 'ON_NET': [on_net],
43
+ 'ORANGE': [orange],
44
+ 'TIGO': [tigo],
45
+ 'REGULARITY':[regularity],
46
+ 'FREQ_TOP_PACK': [freq_top_pack]
47
+ })
48
+
49
+ prediction = clf.predict(input_df)
50
+
51
+
52
+
53
+ churn_label = "Customer will churn" if prediction == 1 else "Customer will not churn"
54
+ result = {
55
+ 'text': churn_label, # Use the churn label as 'text'
56
+ 'entities': [] # You can leave 'entities' as an empty list if no entities need highlighting
57
+ }
58
+ print(result)
59
+ return result
60
+
61
+
62
+
63
+ # Create a dropdown menu with labels
64
+ tenure_dropdown = gr.inputs.Dropdown(list(tenure_labels.values()), label="TENURE")
65
+
66
+ iface = gr.Interface(
67
+ fn=predict,
68
+ inputs=[
69
+ tenure_dropdown, # Dropdown instead of slider
70
+ #gr.inputs.Slider(minimum=1, maximum=7, label="TENURE"),
71
+ gr.inputs.Slider(minimum=20, maximum=470000, label="MONTANT"),
72
+ gr.inputs.Slider(minimum=1, maximum=131, label="FREQUENCE_RECH"),
73
+ gr.inputs.Slider(minimum=1, maximum=530000, label="REVENUE"),
74
+ gr.inputs.Slider(minimum=0, maximum=2453, label="ARPU_SEGMENT"),
75
+ gr.inputs.Slider(minimum=1, maximum=91, label="FREQUENCE"),
76
+ gr.inputs.Slider(minimum=1, maximum=1702309, label="DATA_VOLUME"),
77
+ gr.inputs.Slider(minimum=0, maximum=51000, label="ON_NET"),
78
+ gr.inputs.Slider(minimum=0, maximum=12040, label="ORANGE"),
79
+ gr.inputs.Slider(minimum=0, maximum=4174, label="TIGO"),
80
+ gr.inputs.Slider(minimum=0, maximum=624, label="FREQ_TOP_PACK"),
81
+ gr.inputs.Slider(minimum=0, maximum=62, label="REGULARITY")
82
+ ],
83
+
84
+ outputs=output,
85
+ title="Team Paris Customer Churn Prediction App",
86
+ description="Let's Get Started With Some Predictions!"
87
+ )
88
+
89
+ iface.launch()