Spaces:
Runtime error
Runtime error
Efkan Turedi
commited on
Commit
·
0e7d51b
1
Parent(s):
30e3e72
First commit
Browse files- .DS_Store +0 -0
- .gitattributes +1 -0
- README.md +3 -3
- __pycache__/utils.cpython-37.pyc +0 -0
- app.py +112 -0
- images/1610714878100.gif +0 -0
- images/2021_07_21_QR_scientifique_et_technique_V42_VFR.pdf +0 -0
- images/Nutriscore_A.png +0 -0
- images/Nutriscore_B.png +0 -0
- images/Nutriscore_C.png +0 -0
- images/Nutriscore_D.png +0 -0
- images/Nutriscore_E.png +0 -0
- images/etiquettes-alimentaires-5.webp +0 -0
- model.pickle +3 -0
- requirements.txt +4 -0
- utils.py +23 -0
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
.gitattributes
CHANGED
@@ -25,3 +25,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: Nutriscore_app
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
app_file: app.py
|
8 |
pinned: false
|
|
|
1 |
---
|
2 |
title: Nutriscore_app
|
3 |
+
emoji: 🚀
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: purple
|
6 |
sdk: gradio
|
7 |
app_file: app.py
|
8 |
pinned: false
|
__pycache__/utils.cpython-37.pyc
ADDED
Binary file (617 Bytes). View file
|
|
app.py
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pickle
|
3 |
+
import pandas as pd
|
4 |
+
from utils import *
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
import matplotlib.image as mpimg
|
7 |
+
import sklearn
|
8 |
+
|
9 |
+
with open('./model.pickle', 'rb') as model_file:
|
10 |
+
pipeline = pickle.load(model_file)
|
11 |
+
|
12 |
+
|
13 |
+
def image_score(score):
|
14 |
+
if score == 'a':
|
15 |
+
return mpimg.imread('./images/Nutriscore_A.png')
|
16 |
+
if score == 'b':
|
17 |
+
return mpimg.imread('./images/Nutriscore_B.png')
|
18 |
+
if score == 'c':
|
19 |
+
return mpimg.imread('./images/Nutriscore_C.png')
|
20 |
+
if score == 'd':
|
21 |
+
return mpimg.imread('./images/Nutriscore_D.png')
|
22 |
+
if score == 'e':
|
23 |
+
return mpimg.imread('./images/Nutriscore_E.png')
|
24 |
+
|
25 |
+
|
26 |
+
def greet(energy, saturated_fats, sugars, fibres, proteins, salt):
|
27 |
+
"""
|
28 |
+
This is our main predict function
|
29 |
+
"""
|
30 |
+
data_file = pd.DataFrame(columns={
|
31 |
+
'energy-kcal_100g',
|
32 |
+
'saturated-fat_100g',
|
33 |
+
'sugars_100g',
|
34 |
+
'fiber_100g',
|
35 |
+
'proteins_100g',
|
36 |
+
'salt_100g'
|
37 |
+
})
|
38 |
+
|
39 |
+
data_file = data_file.append({
|
40 |
+
'energy-kcal_100g':float(energy),
|
41 |
+
'saturated-fat_100g':float(saturated_fats),
|
42 |
+
'sugars_100g':float(sugars),
|
43 |
+
'fiber_100g':float(fibres),
|
44 |
+
'proteins_100g':float(proteins),
|
45 |
+
'salt_100g':float(salt)
|
46 |
+
},ignore_index=True)
|
47 |
+
|
48 |
+
nutrigrade = pipeline.predict(data_file)
|
49 |
+
return image_score(nutrigrade[0])
|
50 |
+
|
51 |
+
description = (
|
52 |
+
"Cette inferface vous donne la possibilité de calculer une estimation "\
|
53 |
+
"du nutriscore du produit de votre choix. Pour cela, vous devez vous munir des valeurs\n"\
|
54 |
+
"nutritionnelles du produit, qui se trouvent très souvent sur l'arrière du packaging."
|
55 |
+
)
|
56 |
+
|
57 |
+
article = (
|
58 |
+
"<h2>Aide à l'utilisation</h2>"+
|
59 |
+
'<p><ul><li>Veuillez mettre vos nombres avec des "." et non pas des virgules</li>'+
|
60 |
+
'<li>Veuillez remplir toutes les cases. Si un champ est manquant sur votre étiquette, veuillez remplir le champ avec la valeur 0</li>'+
|
61 |
+
'<li>Si la valeur "sels" n"est pas disponible, veuillez mettre la valeur sodium * 2.5. Cas échéant mettre la valeur 0</li>'+
|
62 |
+
"<li>Le score peut mettre jusqu'à 5 secondes pour s'afficher à la première utilisation</li>"+
|
63 |
+
'<li>Veuillez bien choisir les valeurs pour 100g de produit</li></ul></p>'+
|
64 |
+
'<br>'+
|
65 |
+
"<h2>Informations supplémentaires</h2>"+
|
66 |
+
"<p><ul><li>Notre algorithme se base sur les quantités d'energie, d'acide gras saturés, de sucres, de fibre, de protéines et de sels pour estimer le nutriscore</li>"+
|
67 |
+
"<li>Notre analyse repose sur l'hypothèse que ces 6 facteurs sont les composantes principales du Nustriscore</li>"+
|
68 |
+
"<li>Nous avons entrainé nos modèles sur un échantillon de 350,000 produits</li>"+
|
69 |
+
"<li>Quelques chiffres sur le nutriscore: <a href='https://solidarites-sante.gouv.fr/IMG/pdf/nutriscorebilan3ans.pdf'>Lien</a></li></ul></p>"
|
70 |
+
)
|
71 |
+
|
72 |
+
energy_kcal_100g = gr.inputs.Number(
|
73 |
+
label = 'Energy per 100g (in kcal)'
|
74 |
+
)
|
75 |
+
|
76 |
+
saturated_fats = gr.inputs.Number(
|
77 |
+
label = 'Saturated fats per 100g (in g)'
|
78 |
+
)
|
79 |
+
|
80 |
+
sugars = gr.inputs.Number(
|
81 |
+
label = 'Sugars per 100g (in g)'
|
82 |
+
)
|
83 |
+
|
84 |
+
fibres = gr.inputs.Number(
|
85 |
+
label = 'Fibres per 100g (in g)'
|
86 |
+
)
|
87 |
+
|
88 |
+
proteins = gr.inputs.Number(
|
89 |
+
label = 'Proteins per 100g (in g)'
|
90 |
+
)
|
91 |
+
|
92 |
+
salt = gr.inputs.Number(
|
93 |
+
label = 'Salt per 100g (in g) (Note: Salt = Sodium * 2.5)'
|
94 |
+
)
|
95 |
+
|
96 |
+
image = gr.outputs.Image(
|
97 |
+
label = 'Le Nutriscore estimé est:'
|
98 |
+
)
|
99 |
+
|
100 |
+
iface = gr.Interface(
|
101 |
+
fn=greet,
|
102 |
+
inputs=[energy_kcal_100g,saturated_fats,sugars,fibres,proteins,salt],
|
103 |
+
outputs=image,
|
104 |
+
article = article,
|
105 |
+
title = 'Estimation de Nutriscore (Beta)',
|
106 |
+
description = description,
|
107 |
+
allow_flagging='never',
|
108 |
+
theme='default'
|
109 |
+
)
|
110 |
+
|
111 |
+
|
112 |
+
iface.launch()
|
images/1610714878100.gif
ADDED
![]() |
images/2021_07_21_QR_scientifique_et_technique_V42_VFR.pdf
ADDED
Binary file (1.81 MB). View file
|
|
images/Nutriscore_A.png
ADDED
![]() |
images/Nutriscore_B.png
ADDED
![]() |
images/Nutriscore_C.png
ADDED
![]() |
images/Nutriscore_D.png
ADDED
![]() |
images/Nutriscore_E.png
ADDED
![]() |
images/etiquettes-alimentaires-5.webp
ADDED
![]() |
model.pickle
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a9c91a2d413b5a0c840eb0350ef0a4b42a9f956f45605b63416194ff13eea5f7
|
3 |
+
size 957152302
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==2.7.0
|
2 |
+
matplotlib==3.4.3
|
3 |
+
pandas==1.3.4
|
4 |
+
scikit-learn==1.0.2
|
utils.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def grader_food(x):
|
2 |
+
if x<=-1:
|
3 |
+
return 'a'
|
4 |
+
elif (x>-1)&(x<=2):
|
5 |
+
return 'b'
|
6 |
+
elif (x>2)&(x<=10):
|
7 |
+
return 'c'
|
8 |
+
elif (x>10)&(x<=18):
|
9 |
+
return 'd'
|
10 |
+
else:
|
11 |
+
return 'e'
|
12 |
+
|
13 |
+
def grader_beverages(x):
|
14 |
+
if (x<=0):
|
15 |
+
return 'a'
|
16 |
+
elif (x>0)&(x<=1):
|
17 |
+
return 'b'
|
18 |
+
elif (x>1)&(x<=5):
|
19 |
+
return 'c'
|
20 |
+
elif (x>5)&(x<=9):
|
21 |
+
return 'd'
|
22 |
+
else:
|
23 |
+
return 'e'
|