Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Fonction de prédiction
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import joblib
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import numpy as np
|
| 6 |
+
# importer les encodeurs
|
| 7 |
+
encoder = joblib.load('encoder_Extracurricular.joblib')
|
| 8 |
+
#for i in range(len(cat_data.columns)):
|
| 9 |
+
# encoders.append(joblib.load(f'{cat_data.columns[i]}_encoder.joblib'))
|
| 10 |
+
|
| 11 |
+
# importer le modèle
|
| 12 |
+
from keras.models import load_model
|
| 13 |
+
model = load_model('DNN_model.h5')
|
| 14 |
+
# importer le scaler
|
| 15 |
+
scaler = joblib.load('scaler.joblib')
|
| 16 |
+
# Fonction de prédiction simple
|
| 17 |
+
def prediction_func(Hours_Studied,Previous_Scores,Extracurricular_Activities,Sleep_Hours,Sample_Question_Papers_Practiced):
|
| 18 |
+
#encoder
|
| 19 |
+
Extracurricular_Activities = encoder.transform([Extracurricular_Activities])[0]
|
| 20 |
+
x_new = np.array([Hours_Studied,Previous_Scores,Extracurricular_Activities,Sleep_Hours,Sample_Question_Papers_Practiced]).reshape(1, -1)
|
| 21 |
+
# normaliser les valeurs
|
| 22 |
+
x_new = scaler.transform(x_new)
|
| 23 |
+
# prédire la valeur
|
| 24 |
+
y_pred = np.round(model.predict(x_new))[0][0]
|
| 25 |
+
# retourner
|
| 26 |
+
return y_pred
|
| 27 |
+
|
| 28 |
+
# load les valeurs uniques
|
| 29 |
+
#uniques = []
|
| 30 |
+
#for i in range(len(cat_data.columns)):
|
| 31 |
+
# uniques.append(joblib.load(f'{cat_data.columns[i]}_unique.joblib'))
|
| 32 |
+
# créer les inputs Hours_Studied,Previous_Scores,Extracurricular_Activities,Sleep_Hours,Sample_Question_Papers_Practiced,Performance_Index
|
| 33 |
+
inputs = [
|
| 34 |
+
gr.Number(label="hours Studies"),
|
| 35 |
+
gr.Number(label="Previous score"),
|
| 36 |
+
gr.Dropdown(choices=['No', 'Yes'], label="Extracurricular_Activities"),
|
| 37 |
+
gr.Number( label="Sleep_Hours"),
|
| 38 |
+
gr.Number(label="Sample_Question_Papers_Practiced")
|
| 39 |
+
|
| 40 |
+
]
|
| 41 |
+
# créer les outputs
|
| 42 |
+
outputs = gr.Textbox(label = 'Performance')
|
| 43 |
+
# Interface
|
| 44 |
+
Interface =gr.Interface(fn = prediction_func,
|
| 45 |
+
inputs = inputs,
|
| 46 |
+
outputs = outputs,
|
| 47 |
+
title = 'Student performance'
|
| 48 |
+
,theme='NoCrypt/miku')
|
| 49 |
+
Interface.launch()
|