File size: 2,692 Bytes
22b6431
 
 
 
 
 
 
 
 
 
cde32ef
22b6431
b428c1d
22b6431
b428c1d
8743ef1
22b6431
b428c1d
8743ef1
22b6431
 
 
b428c1d
 
d8c659e
8743ef1
f789872
 
 
 
 
 
d8c659e
 
 
 
 
 
 
 
 
 
 
 
 
dc507ef
22b6431
 
 
 
 
 
 
 
 
 
 
 
 
d8c659e
 
 
 
 
 
 
 
22b6431
 
d8c659e
22b6431
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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()