Spaces:
Sleeping
Sleeping
| import joblib | |
| import numpy as np | |
| from keras.models import load_model | |
| import gradio as gr | |
| import pandas as pd | |
| # Télécharger l'encoder | |
| encoder = joblib.load('Extracurricular.joblib') | |
| # Télécharger le sacler | |
| scaler = joblib.load('scaler.joblib') | |
| # Le modèle | |
| model = load_model('DNN_model.keras') | |
| def predict_func(hours_studied, previous_scores, Extracurricular_Activities, sleep_hours, Sample_Question_Papers_Practiced): | |
| # encoder la valeur de Extracurriclar Activities using map | |
| Extracurricular_Activities = encoder.transform([Extracurricular_Activities])[0] | |
| # vecteur des valeurs numeriques | |
| x_new=np.array([hours_studied,previous_scores,Extracurricular_Activities,sleep_hours,Sample_Question_Papers_Practiced]).reshape(1, -1) | |
| x_new=scaler.transform(x_new) | |
| # Prediction | |
| y_pred = model.predict(x_new) | |
| #y_pred = round(y_pred[0][0],2) | |
| return round(y_pred[0][0],2) | |
| # # Télécharger l'encoder | |
| # encoder = joblib.load('Extracurricular.joblib') | |
| # # Télécharger le sacler | |
| # scaler = joblib.load('scaler.joblib') | |
| # # Le modèle | |
| # model = load_model('/content/DNN_model.h5') | |
| def Pred_func_csv(file): | |
| # Lire le fichier csv | |
| df = pd.read_csv(file) | |
| predictions = [] | |
| # Boucle sur les lignes du dataframe | |
| for row in df.iloc[:, :].values: | |
| y_pred = predict_func(row[0], row[1],row[2], row[3],row[4]) | |
| # ajouter la prediction sur List_predictions | |
| predictions.append(y_pred) | |
| df['Performance_Index'] = predictions | |
| df.to_csv('predictions.csv', index = False) | |
| return 'predictions.csv' | |
| demo=gr.Blocks(theme = 'NoCrypt/miku') | |
| # Créer les inputs | |
| inputs = [gr.Number(label='Hours_Studied'), | |
| gr.Number(label='Previous_Scores'), | |
| gr.Radio(choices=['Yes', 'No'], label='Extracurricular_Activities'), | |
| gr.Number(label='Sleep_Hours'), | |
| gr.Number(label='Sample_Question_Papers_Practiced')] | |
| # Créer les outputs | |
| outputs = gr.Textbox(label='Performance_Index') | |
| # Créer l'interface 1 | |
| interface1 = gr.Interface(fn = predict_func, | |
| inputs = inputs, | |
| outputs = outputs, | |
| title="Prédire la performance d'un individu", | |
| ) | |
| # Créer l'interface 2 | |
| interface2 = gr.Interface(fn = Pred_func_csv, | |
| inputs = gr.File(label='Upload a csv file'), | |
| outputs = gr.File(label='Download a csv file'), | |
| title="Prédiction multiple de la performance d'un individu" | |
| ) | |
| # faire un tabbing des interfaces | |
| with demo: | |
| gr.TabbedInterface([interface1, interface2], ['Simple Prediction', 'Prédiction multiple']) | |
| # lancer l'interface | |
| demo.launch() |