Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
# Cargar modelo de reconocimiento de alimentos
|
| 8 |
+
model_name = "nateraw/food101" # modelo preentrenado Food-101
|
| 9 |
+
model = AutoModelForImageClassification.from_pretrained(model_name)
|
| 10 |
+
extractor = AutoFeatureExtractor.from_pretrained(model_name)
|
| 11 |
+
|
| 12 |
+
# Cargar tabla de nutrici贸n de ejemplo
|
| 13 |
+
# Debes subir nutrition.csv despu茅s con columnas: food, calories, protein, fat, carbs
|
| 14 |
+
nutrition_df = pd.read_csv("nutrition.csv")
|
| 15 |
+
|
| 16 |
+
def analizar_comida(imagen: Image):
|
| 17 |
+
# Preprocesar imagen
|
| 18 |
+
inputs = extractor(images=imagen, return_tensors="pt")
|
| 19 |
+
with torch.no_grad():
|
| 20 |
+
outputs = model(**inputs)
|
| 21 |
+
|
| 22 |
+
predicted_class = model.config.id2label[outputs.logits.]()_
|