File size: 1,065 Bytes
ac9ad30
 
 
ca7f933
ac9ad30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ca7f933
 
 
ac9ad30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.

# %% auto 0
__all__ = ['img', 'path', 'filename', 'learn', 'searches', 'title', 'description', 'examples', 'demo', 'classify_image']

# %% app.ipynb 1
from fastbook import search_images_ddg
from fastdownload import download_url
from fastai.vision.all import *
import gradio as gr
import torch

# %% app.ipynb 4
img = PILImage.create('grizzly.jpg')
img.thumbnail((192,192))
img

# %% app.ipynb 5
path = Path()
filename = path.ls(file_exts='.pkl')
filename[0].name

# %% app.ipynb 6
learn = load_learner(filename[0].name)

# %% app.ipynb 8
searches = ("grizzly bears","black bears","teddy bears")

def classify_image(img):
    pred,idx,probs = learn.predict(img)
    return dict(zip(searches, map(float,probs)))

# %% app.ipynb 10
title = "FastAi demo"
description = "This demo is the original"
examples = ["grizzly.jpg"]

# %% app.ipynb 11
demo = gr.Interface(
    fn=classify_image,
    inputs="image",
    outputs="label",
    title=title,
    description=description,
    examples = examples)
demo.launch()