# AUTOGENERATED! DO NOT EDIT! File to edit: SceneCat.ipynb. | |
# %% auto 0 | |
__all__ = ['nbpath', 'learn_inf', 'examples', 'intf', 'classify_img'] | |
# %% SceneCat.ipynb 3 | |
from fastai.vision.all import * | |
import gradio as gr | |
# %% SceneCat.ipynb 26 | |
# carregando o arquivo com o modelo para inferência | |
nbpath = Path() | |
learn_inf = load_learner(nbpath/'scenecat.pkl') | |
# %% SceneCat.ipynb 28 | |
# Vamos criar uma função para categorizar as imagens | |
def classify_img(img): | |
pred, idx, probs = learn_inf.predict(img) | |
return dict(zip(learn_inf.dls.vocab, map(float, probs))) | |
# %% SceneCat.ipynb 31 | |
examples = ['test_anime.jpg', 'test_cartoon.jpg', 'test_live_action.webp'] | |
intf = gr.Interface(fn=classify_img, inputs=gr.Image(), outputs=gr.Label(), examples=examples, flagging_dir='flagged') | |
intf.launch(inline=False) | |