Spaces:
Build error
Build error
| import gradio as gr | |
| import requests | |
| import json | |
| import os | |
| API_URL = "https://api-inference.huggingface.co/models/davidaf3/ReverseNutrition_TFIngPort" | |
| 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 if element["score"] > 0] | |
| app = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Image(type="filepath"), | |
| outputs=gr.Dataframe(headers=["ingredient", "amount per 100g (in g)"]), | |
| allow_flagging="never", | |
| description= | |
| "Upload food images and get an estimation about their ingredients and the ingredient proportions.\ | |
| The model used is [ReverseNutrition_TFIngPort](https://huggingface.co/davidaf3/ReverseNutrition_TFIngPort).\ | |
| If the output table shows an error, wait until the model is loaded." | |
| ) | |
| app.launch() |