Spaces:
Runtime error
Runtime error
import gradio as gr | |
from PIL import Image | |
import torch | |
from torchvision.io import read_image | |
from transformers import ViTImageProcessor,pipeline | |
model = ViTImageProcessor.from_pretrained('SeyedAli/Food-Image-Classification-VIT') | |
def FoodClassification(image): | |
image = read_image(image) | |
# Encode your PIL Image as a JPEG without writing to disk | |
# buffer = io.BytesIO(image) | |
# YourImage.save(buffer, format='JPEG', quality=75) | |
# # You probably want | |
# desiredObject = buffer.getbuffer() | |
pipline = pipeline(task="image-classification", model=model) | |
#output=pipline(model(Image.open(desiredObject), return_tensors='pt')) | |
output=pipline(image, return_tensors='pt')) | |
return output | |
iface = gr.Interface(fn=FoodClassification, inputs="image", outputs="text") | |
iface.launch(share=False) |