Spaces:
Sleeping
Sleeping
File size: 760 Bytes
e1584c5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
import torch
from transformers import AutoImageProcessor, AutoModelForImageClassification
model_id = "microsoft/food101-resnet50"
processor = AutoImageProcessor.from_pretrained(model_id)
model = AutoModelForImageClassification.from_pretrained(model_id)
def classify_food(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]
interface = gr.Interface(
fn=classify_food,
inputs=gr.Image(type="pil"),
outputs=gr.Textbox(),
title="Food Image Classification",
description="Upload a food image and the model will classify it."
)
interface.launch() |