File size: 857 Bytes
cd254a4
1a410aa
d933416
cd254a4
23e6b97
c4a9309
cd254a4
c4a9309
cd254a4
 
4d335eb
2417ee3
4d335eb
 
 
 
 
 
2417ee3
cd254a4
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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_audio_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()
        # 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)