Spaces:
Runtime error
Runtime error
import gradio as gr | |
from PIL import Image | |
import tempfile | |
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): | |
with tempfile.NamedTemporaryFile(suffix=".png") as temp_image_file: | |
# Copy the contents of the uploaded image file to the temporary file | |
# temp_image_file.write(open(image, "rb").read()) | |
# temp_image_file.flush() | |
Image.fromarray(image).save(temp_image_file.name) | |
# Load the image file using torchvision | |
image = read_image(temp_image_file.name) | |
pipline = pipeline(task="image-classification", model=model) | |
output=pipline(image, return_tensors='pt') | |
return output | |
iface = gr.Interface(fn=FoodClassification, inputs="image", outputs="text") | |
iface.launch(share=False) |