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