Jamal914's picture
Update app.py
3e0b35a
# pip install scikit-learn
#
import gradio as gr
import pandas as pd
import pickle
# from sklearn.pipeline import Pipeline
# from sklearn.ensemble import RandomForestClassifier
# from sklearn.preprocessing import StandardScaler, LabelEncoder
# from sklearn.impute import SimpleImputer
# from imblearn.over_sampling import RandomOverSampler
# from sklearn.preprocessing import FunctionTransformer
# import joblib
xtrain= pd.read_csv('Xtrains.csv')
ytrain=pd.read_csv('Ytrains.csv')
# Loading Models
with open("model.pkl", "rb") as f:
clf = pickle.load(f)
clf.fit(xtrain, ytrain.values.ravel())
tenure_labels = {
0: "3-6 months",
1: "6-9 months",
2: "9-12 months",
3: "12-15 months",
4: "15-18 months",
5: "18-21 months",
6: "21-24 months",
7: "> 24 months"
}
# Reverse the mapping for predictions
tenure_values = {v: k for k, v in tenure_labels.items()}
def predict(tenure, montant, freq_rech, revenue, arpu, freq, data_vol, on_net, orange, tigo, freq_top_pack, regularity):
tenure_value = tenure_values[tenure]
input_df = pd.DataFrame({
'TENURE': [tenure_value],
'MONTANT': [montant],
'FREQUENCE_RECH': [freq_rech],
'REVENUE': [revenue],
'ARPU_SEGMENT': [arpu],
'FREQUENCE': [freq],
'DATA_VOLUME': [data_vol],
'ON_NET': [on_net],
'ORANGE': [orange],
'TIGO': [tigo],
'REGULARITY':[regularity],
'FREQ_TOP_PACK': [freq_top_pack]
})
prediction = clf.predict(input_df)
churn_label = "Customer will churn" if prediction == 1 else "Customer will not churn"
return churn_label
# result = {
# 'Churn Prediction': churn_label,
# }
# print(result['Churn Prediction'])
# return result
# Create a dropdown menu with labels
tenure_dropdown = gr.inputs.Dropdown(list(tenure_labels.values()), label="TENURE")
iface = gr.Interface(
fn=predict,
inputs=[
tenure_dropdown, # Dropdown instead of slider
#gr.inputs.Slider(minimum=1, maximum=7, label="TENURE"),
gr.inputs.Slider(minimum=20, maximum=470000, label="MONTANT"),
gr.inputs.Slider(minimum=1, maximum=131, label="FREQUENCE_RECH"),
gr.inputs.Slider(minimum=1, maximum=530000, label="REVENUE"),
gr.inputs.Slider(minimum=0, maximum=2453, label="ARPU_SEGMENT"),
gr.inputs.Slider(minimum=1, maximum=91, label="FREQUENCE"),
gr.inputs.Slider(minimum=1, maximum=1702309, label="DATA_VOLUME"),
gr.inputs.Slider(minimum=0, maximum=51000, label="ON_NET"),
gr.inputs.Slider(minimum=0, maximum=12040, label="ORANGE"),
gr.inputs.Slider(minimum=0, maximum=4174, label="TIGO"),
gr.inputs.Slider(minimum=0, maximum=624, label="FREQ_TOP_PACK"),
gr.inputs.Slider(minimum=0, maximum=62, label="REGULARITY")
],
outputs=gr.outputs.Label(),
title="Team Paris Customer Churn Prediction App",
description="Let's Get Started With Some Predictions!"
)
iface.launch()