File size: 1,647 Bytes
432d3f4
 
 
bfd8146
42ed78b
604f9e9
42ed78b
 
 
0f0115a
42ed78b
0f0115a
42ed78b
0f0115a
42ed78b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d04399
42ed78b
 
 
 
 
 
 
 
 
 
 
2670d3f
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
import gradio as gr


from sklearn import preprocessing
import pandas as pd
import joblib
import os
import numpy as np

model =  joblib.load("nutriscore_model.pkl")

labelencoder = joblib.load("labelencoder.pkl")

std_scale = joblib.load("std_scale.pkl")

cols = ['energy_kcal_100g', 'fat_100g', 'saturated_fat_100g',
        'carbohydrates_100g', 'sugars_100g', 'proteins_100g', 'salt_100g']

temp = pd.DataFrame(columns=cols)

def greet(energy_kcal_100g, fat_100g, saturated_fat_100g,
       carbohydrates_100g, sugars_100g, proteins_100g, salt_100g):

  total =  fat_100g  + carbohydrates_100g +  proteins_100g + salt_100g
  if total > 100:
      return "Erreur de saisie : total des informations nutritionnelles pour 100g > 100"

  if saturated_fat_100g > fat_100g:
      return 'Erreur de saisie : graisses saturées > graisses'

  if sugars_100g > carbohydrates_100g:
      return 'Erreur de saisie : sucres > glucides'

  else:

    temp['energy_kcal_100g'] = [energy_kcal_100g]
    temp['fat_100g'] = [fat_100g]
    temp['saturated_fat_100g'] = [saturated_fat_100g]
    temp['carbohydrates_100g'] = [carbohydrates_100g]
    temp['sugars_100g'] = [sugars_100g]
    temp['proteins_100g'] = [proteins_100g]
    temp['salt_100g'] = [salt_100g]

    X = temp.values

    temp_scaled = std_scale.transform(X)

      # Make prediction
    y_pred = model.predict(temp)

    # reverse label encoding
    y_pred = labelencoder.inverse_transform(y_pred)

    return y_pred[0].capitalize()

iface = gr.Interface(fn=greet, inputs=["number", "number", "number", "number","number", "number", "number"],
                     outputs="text")
iface.launch()