|
|
|
|
|
|
|
__all__ = ['plt', 'learner', 'categories', 'image', 'label', 'examples', 'intf', 'classify_img'] |
|
|
|
|
|
from fastai.vision.all import * |
|
import gradio as gr |
|
|
|
|
|
import pathlib |
|
plt = platform.system() |
|
if plt == 'Windows': pathlib.PosixPath = pathlib.WindowsPath |
|
|
|
|
|
learner = load_learner('./export.pkl') |
|
|
|
|
|
categories = 'happy','unhappy' |
|
def classify_img(img): |
|
pred,idx,probs = learner.predict(img) |
|
return dict(zip(categories,map(float,probs))) |
|
|
|
|
|
image = gr.inputs. Image (shape= (192, 192)) |
|
label = gr.outputs. Label () |
|
examples = ['unhappy.jpg','happy.jpg'] |
|
intf = gr. Interface(fn=classify_img, inputs=image, outputs=label, examples=examples) |
|
intf.launch(inline=False) |
|
|