File size: 866 Bytes
ca1d264 328df23 ca1d264 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import numpy as np
import gradio as gr
from transformers import AutoImageProcessor, AutoModelForImageClassification
from PIL import Image
processor = AutoImageProcessor.from_pretrained("microsoft/swin-tiny-patch4-window7-224")
model = AutoModelForImageClassification.from_pretrained("microsoft/swin-tiny-patch4-window7-224")
def classifier(image):
image = Image.open(image.raw)
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
# model predicts one of the 1000 ImageNet classes
predicted_class_idx = logits.argmax(-1).item()
return model.config.id2label[predicted_class_idx]
food = gr.Interface(
fn=classifier,
inputs=gr.Image(type="pil"),
outputs="text",
title = "what's your eating?",
description = "A simple model for food classification"
)
food.launch() |