Spaces:
Runtime error
Runtime error
Commit
·
42ed78b
1
Parent(s):
e60235e
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,58 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
|
|
|
|
3 |
|
4 |
+
from sklearn.preprocessing import LabelEncoder
|
5 |
+
import pandas as pd
|
6 |
+
import joblib
|
7 |
+
import os
|
8 |
+
import numpy as np
|
9 |
+
|
10 |
+
model = joblib.load("nutriscore_model.pkl")
|
11 |
+
|
12 |
+
labelencoder = joblib.load("labelencoder.pkl")
|
13 |
+
|
14 |
+
std_scale = joblib.load("std_scale.pkl")
|
15 |
+
|
16 |
+
cols = ['energy_kcal_100g', 'fat_100g', 'saturated_fat_100g',
|
17 |
+
'carbohydrates_100g', 'sugars_100g', 'proteins_100g', 'salt_100g']
|
18 |
+
|
19 |
+
temp = pd.DataFrame(columns=cols)
|
20 |
+
|
21 |
+
def greet(energy_kcal_100g, fat_100g, saturated_fat_100g,
|
22 |
+
carbohydrates_100g, sugars_100g, proteins_100g, salt_100g):
|
23 |
+
|
24 |
+
total = fat_100g + carbohydrates_100g + proteins_100g + salt_100g
|
25 |
+
if total > 100:
|
26 |
+
return "Erreur de saisie : total des informations nutritionnelles pour 100g > 100"
|
27 |
+
|
28 |
+
if saturated_fat_100g > fat_100g:
|
29 |
+
return 'Erreur de saisie : graisses saturées > graisses'
|
30 |
+
|
31 |
+
if sugars_100g > carbohydrates_100g:
|
32 |
+
return 'Erreur de saisie : sucres > glucides'
|
33 |
+
|
34 |
+
else:
|
35 |
+
|
36 |
+
temp['energy_kcal_100g'] = [energy_kcal_100g]
|
37 |
+
temp['fat_100g'] = [fat_100g]
|
38 |
+
temp['saturated_fat_100g'] = [saturated_fat_100g]
|
39 |
+
temp['carbohydrates_100g'] = [carbohydrates_100g]
|
40 |
+
temp['sugars_100g'] = [sugars_100g]
|
41 |
+
temp['proteins_100g'] = [proteins_100g]
|
42 |
+
temp['salt_100g'] = [salt_100g]
|
43 |
+
|
44 |
+
X = temp.values
|
45 |
+
|
46 |
+
temp_scaled = std_scale.transform(temp_scaled)
|
47 |
+
|
48 |
+
# Make prediction
|
49 |
+
y_pred = model.predict(temp)
|
50 |
+
|
51 |
+
# reverse label encoding
|
52 |
+
y_pred = labelencoder.inverse_transform(y_pred)
|
53 |
+
|
54 |
+
return y_pred[0].capitalize()
|
55 |
+
|
56 |
+
iface = gr.Interface(fn=greet, inputs=["number", "number", "number", "number","number", "number", "number"],
|
57 |
+
outputs="text")
|
58 |
iface.launch()
|