davidaf3 commited on
Commit
e42a40a
1 Parent(s): 995915f
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import json
4
+ import os
5
+
6
+ API_URL = "https://api-inference.huggingface.co/models/davidaf3/ReverseNutrition_FCNutr"
7
+ headers = {"Authorization": f"Bearer {os.environ['API_TOKEN']}"}
8
+
9
+ def predict(image_file):
10
+ with open(image_file, "rb") as f:
11
+ data = f.read()
12
+ response = requests.request("POST", API_URL, headers=headers, data=data)
13
+ predictions = json.loads(response.content.decode("utf-8"))
14
+ return [[element["label"], element["score"]] for element in predictions]
15
+
16
+ app = gr.Interface(
17
+ fn=predict,
18
+ inputs=gr.Image(type="filepath"),
19
+ outputs=gr.Dataframe(headers=["name", "amount per 100g (in kcal or g)"]),
20
+ allow_flagging="never",
21
+ description=
22
+ "Upload food images and get an estimation about their nutrition facts.\
23
+ The model used is [ReverseNutrition_FCNutr](https://huggingface.co/davidaf3/ReverseNutrition_FCNutr).\
24
+ If the output table shows an error, wait until the model is loaded."
25
+ )
26
+
27
+ app.launch()