|
|
|
|
|
|
|
__all__ = ['img', 'path', 'filename', 'learn', 'searches', 'title', 'description', 'examples', 'demo', 'classify_image'] |
|
|
|
|
|
from fastbook import search_images_ddg |
|
from fastdownload import download_url |
|
from fastai.vision.all import * |
|
import gradio as gr |
|
import torch |
|
|
|
|
|
img = PILImage.create('grizzly.jpg') |
|
img.thumbnail((192,192)) |
|
img |
|
|
|
|
|
path = Path() |
|
filename = path.ls(file_exts='.pkl') |
|
filename[0].name |
|
|
|
|
|
learn = load_learner(filename[0].name) |
|
|
|
|
|
searches = ("grizzly bears","black bears","teddy bears") |
|
|
|
def classify_image(img): |
|
pred,idx,probs = learn.predict(img) |
|
return dict(zip(searches, map(float,probs))) |
|
|
|
|
|
title = "FastAi demo" |
|
description = "This demo is the original" |
|
examples = ["grizzly.jpg"] |
|
|
|
|
|
demo = gr.Interface( |
|
fn=classify_image, |
|
inputs="image", |
|
outputs="label", |
|
title=title, |
|
description=description, |
|
examples = examples) |
|
demo.launch() |
|
|