File size: 987 Bytes
77282d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c545af
 
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
48
49
50
51
52
53
54
55
56
57
58
59
# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.15.1
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# !conda install conda=23.7.3 -y

# !nbdev_migrate

#|export
# !pip install gradio

#|export
from fastai.vision.all import *
import gradio as gd

im = PILImage.create('car.jpg')
im.thumbnail((192,192))
im

#|export
learn = load_learner('export.pkl')

# %time learn.predict(im)

# +
#|export
categories = ('car','motorbike')

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


# -

classify_images(im)

# +
#|export
image = gd.inputs.Image(shape=(192,192))
label = gd.outputs.Label()
examples = ['car.jpg','bike.jpg']

intf = gd.Interface(fn = classify_images,inputs = image, outputs = label, examples = examples)
intf.launch(inline=False)