|
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)))
|
|
|
|
|
|
image = gr.inputs.Image(shape=(192,192))
|
|
|
|
label = gr.outputs.Label()
|
|
|
|
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)
|
|
|