-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
115 lines (97 loc) · 3.14 KB
/
app.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
"""app.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1nz2lFQqlwhB4IJTlNYeY6c7GhjHa6OPB
"""
from fastai.vision.all import *
from fastai.vision.all import load_learner
import nbdev
import os
import gradio as gr
import pathlib
# from google.colab import drive
# drive.mount('/content/drive/')
temp = pathlib.WindowsPath
pathlib.WindowsPath = pathlib.PosixPath
model_dir = "/content/drive/MyDrive/Learnings/fai/models/parrot-recognizer-v3.pkl"
model = load_learner(model_dir)
parrot_species = ['african grey parrot',
'australian king parrot',
'blue lorikeet',
'blue-and-yellow macaw',
'blue-headed parrot',
'budgerigar',
'burrowing parrot',
'caique parrot',
'catalina macaw',
'chestnut-fronted macaw',
'cockatiels',
'crimson rosella',
'cuban amazon',
'eclectus parrot',
'galah',
'golden parakeet',
'great green macaw',
'great hanging parrot',
'greater vasa parrot',
'hahn_s macaws',
'hooded parrot',
'hyacinth macaw',
'kea',
'kākāpō',
'lovebirds',
'monk parakeet',
'orange-winged amazon',
'palm cockatoo',
'parrotlet',
'plum-headed parakeet',
'puerto rican amazon',
'rainbow lorikeet',
'red-breasted parakeet',
'red-crowned amazon',
'red-crowned parakeet',
'red-fan parrot',
'red-shouldered macaw',
'red-tailed black cockatoos',
'rose-ringed parakeet',
'saint vincent amazon',
'scarlet macaw',
'senegal parrot',
'spixs macaw',
'sun conure',
'thick-billed parrot',
'turquoise-fronted amazon',
'vernal hanging parrot',
'white cockatoo',
'yellow-collared macaws',
'yellow-headed amazon']
def recognize_image(image):
pred, idx, probs = model.predict(image)
return dict(zip(parrot_species, map(float, probs)))
# im = "/content/drive/MyDrive/Learnings/fai/test_images/unknown_12.jpg"
# img = PILImage.create(im)
# img.thumbnail((192,192))
# img
# recognize_image(img)
image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = [
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_00.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_01.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_02.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_03.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_04.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_05.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_06.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_07.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_08.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_09.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_10.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_11.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_12.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_13.jpg",
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_14.jpg",
]
iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
iface.launch(inline=False, share = True)