File size: 517 Bytes
43a5d5d
 
68d627f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pip install transformers[torch]

from transformers import pipeline
from PIL import Image
import gradio as gr


def get_result_by_image(input_image: gr.Image) -> dict:
    pipe = pipeline("image-classification", model="ivandrian11/vit-fruit-classifier")

    image = Image.fromarray(input_image)
    print(pipe(image))

    sorted_data = sorted(pipe(image), key=lambda x: x["score"], reverse=True)
    return sorted_data[0]


iface = gr.Interface(fn=get_result_by_image, inputs="image", outputs="text")
iface.launch()