Bank_prediction / app.py
abdoulayee's picture
Create app.py
919fee2 verified
import gradio as gr
import joblib
import numpy as np
import pandas as pd
# Liste des colonnes catégorielles
cat_columns = ['job', 'marital', 'education', 'housing', 'loan', 'contact', 'month', 'day_of_week', 'poutcome']
# Charger les encodeurs
encoders = {}
for col in cat_columns:
encoders[col] = joblib.load(f"{col}.joblib")
# Charger l'encodeur de la variable cible
encoder_y = joblib.load("y.joblib")
#from xgboost import XGBClassifier
model = joblib.load("xgb.joblib")
def predict_y(job, marital, education, housing, loan, contact, month, day_of_week, poutcome):
# Créer un DataFrame avec les inputs
input_data = pd.DataFrame([[job, marital, education, housing, loan, contact, month, day_of_week, poutcome]], columns=cat_columns)
# Encoder chaque colonne
for col in cat_columns:
input_data[col] = encoders[col].transform(input_data[col])
# 👉 Ici on simule la prédiction. Remplace par ton vrai modèle :
prediction = model.predict(input_data)
#prediction = np.random.choice([0, 1]) # juste pour test
# Décoder la prédiction si elle est catégorielle
return encoder_y.inverse_transform([prediction])[0]
# Interface Gradio
iface = gr.Interface(
fn=predict_y,
inputs=[
gr.Textbox(label="Job"),
gr.Textbox(label="Marital"),
gr.Textbox(label="Education"),
gr.Textbox(label="Housing"),
gr.Textbox(label="Loan"),
gr.Textbox(label="Contact"),
gr.Textbox(label="Month"),
gr.Textbox(label="Day of Week"),
gr.Textbox(label="Poutcome"),
],
outputs="text",
title="Prédiction Banque - Variable y",
description="Entrez les informations pour prédire la variable y (yes/no)"
)
iface.launch()