davidaf3's picture
Added app
e42a40a
raw
history blame contribute delete
No virus
996 Bytes
import gradio as gr
import requests
import json
import os
API_URL = "https://api-inference.huggingface.co/models/davidaf3/ReverseNutrition_FCNutr"
headers = {"Authorization": f"Bearer {os.environ['API_TOKEN']}"}
def predict(image_file):
with open(image_file, "rb") as f:
data = f.read()
response = requests.request("POST", API_URL, headers=headers, data=data)
predictions = json.loads(response.content.decode("utf-8"))
return [[element["label"], element["score"]] for element in predictions]
app = gr.Interface(
fn=predict,
inputs=gr.Image(type="filepath"),
outputs=gr.Dataframe(headers=["name", "amount per 100g (in kcal or g)"]),
allow_flagging="never",
description=
"Upload food images and get an estimation about their nutrition facts.\
The model used is [ReverseNutrition_FCNutr](https://huggingface.co/davidaf3/ReverseNutrition_FCNutr).\
If the output table shows an error, wait until the model is loaded."
)
app.launch()