import numpy as np import gradio as gr from transformers import AutoImageProcessor, AutoModelForImageClassification from PIL import Image processor = AutoImageProcessor.from_pretrained("Moreza009/HF_CVcourse_FoodClassifier") model = AutoModelForImageClassification.from_pretrained("Moreza009/HF_CVcourse_FoodClassifier") def classifier(image): image = Image.open(image) inputs = processor(images=image, return_tensors="pt") outputs = model(**inputs) logits = outputs.logits predicted_class_idx = logits.argmax(-1).item() return model.config.id2label[predicted_class_idx] food = gr.Interface( fn=classifier, inputs=gr.Image(), outputs="text", title = "what's your eating?", description = "A simple model for food classification" ) food.launch()