File size: 792 Bytes
70feaf9 65d5ed6 70feaf9 65d5ed6 70feaf9 |
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 |
from fastai.vision import *
from fastai.learner import load_learner
from PIL import Image
import gradio as gr
import pathlib, platform
plt = platform.system()
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
learn = load_learner("model.pkl")
categories = list(learn.dls.vocab)
def classify_image(img):
pred, ix, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
# Whats the gradio input type? Image
image = gr.inputs.Image(shape=(192,192))
# Whats the gradio output type? Label
label = gr.outputs.Label()
# Set up some examples
examples = ["examples/kairi.jpg", "examples/riku.jpg", "examples/sora.jpg"]
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)
|