File size: 1,221 Bytes
0d93ff2
fcd5e76
 
0d93ff2
 
 
fcd5e76
0d93ff2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastai.vision.all import load_learner
import gradio as gr

import pathlib
temp=pathlib.PosixPath
pathlib.PosixPath=pathlib.WindowsPath

snake_labels = (
    "Monocled cobra",
    "Egyptian cobra",
    "Black-necked spitting cobra",
    "Samar cobra",
    "Red spitting cobra",
    "Javan spitting cobra",
    "Spectacled cobra",
    "Russell's viper",
    "Horned vipers",
    "Bush vipers",
    "Eyelash viper",
    "Saw-scaled vipers",
    "Banded krait",
    "Black mamba",
    "Inland taipan",
    "Eastern brown snake",
    "Rattle snake",
    "King cobra"
)

model = load_learner('models/snake-recognizer-v0.pkl')

def recognize_snake(photo):
  pred, idx, probs = model.predict(photo)
  return dict(zip(snake_labels, map(float, probs)))


image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = [
    'test data/viper-2.jpg',
    'test data/shutterstock_2062214282-edited-1-scaled.jpg',
    'test data/download (3).jpg',
    'test data/download (4).jpg',
    'test data/Naja_sputatrix.jpg',
    'test data/download (6).jpg',
    'test data/download.jpg'
    ]

iface = gr.Interface(fn=recognize_snake, inputs=image, outputs=label, examples=examples)
iface.launch(inline=False,share=True)