Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
iface = gr.Interface(fn=
|
| 7 |
-
iface.launch()
|
|
|
|
| 1 |
+
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
from fastai.vision.all import load_learner
|
| 4 |
+
import nbdev
|
| 5 |
+
import os
|
| 6 |
import gradio as gr
|
| 7 |
+
import pathlib
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# from google.colab import drive
|
| 11 |
+
# drive.mount('/content/drive/')
|
| 12 |
+
|
| 13 |
+
temp = pathlib.WindowsPath
|
| 14 |
+
pathlib.WindowsPath = pathlib.PosixPath
|
| 15 |
+
|
| 16 |
+
model_dir = "/content/drive/MyDrive/Learnings/fai/models/parrot-recognizer-v3.pkl"
|
| 17 |
+
|
| 18 |
+
model = load_learner(model_dir)
|
| 19 |
+
|
| 20 |
+
parrot_species = ['african grey parrot',
|
| 21 |
+
'australian king parrot',
|
| 22 |
+
'blue lorikeet',
|
| 23 |
+
'blue-and-yellow macaw',
|
| 24 |
+
'blue-headed parrot',
|
| 25 |
+
'budgerigar',
|
| 26 |
+
'burrowing parrot',
|
| 27 |
+
'caique parrot',
|
| 28 |
+
'catalina macaw',
|
| 29 |
+
'chestnut-fronted macaw',
|
| 30 |
+
'cockatiels',
|
| 31 |
+
'crimson rosella',
|
| 32 |
+
'cuban amazon',
|
| 33 |
+
'eclectus parrot',
|
| 34 |
+
'galah',
|
| 35 |
+
'golden parakeet',
|
| 36 |
+
'great green macaw',
|
| 37 |
+
'great hanging parrot',
|
| 38 |
+
'greater vasa parrot',
|
| 39 |
+
'hahn_s macaws',
|
| 40 |
+
'hooded parrot',
|
| 41 |
+
'hyacinth macaw',
|
| 42 |
+
'kea',
|
| 43 |
+
'kākāpō',
|
| 44 |
+
'lovebirds',
|
| 45 |
+
'monk parakeet',
|
| 46 |
+
'orange-winged amazon',
|
| 47 |
+
'palm cockatoo',
|
| 48 |
+
'parrotlet',
|
| 49 |
+
'plum-headed parakeet',
|
| 50 |
+
'puerto rican amazon',
|
| 51 |
+
'rainbow lorikeet',
|
| 52 |
+
'red-breasted parakeet',
|
| 53 |
+
'red-crowned amazon',
|
| 54 |
+
'red-crowned parakeet',
|
| 55 |
+
'red-fan parrot',
|
| 56 |
+
'red-shouldered macaw',
|
| 57 |
+
'red-tailed black cockatoos',
|
| 58 |
+
'rose-ringed parakeet',
|
| 59 |
+
'saint vincent amazon',
|
| 60 |
+
'scarlet macaw',
|
| 61 |
+
'senegal parrot',
|
| 62 |
+
'spixs macaw',
|
| 63 |
+
'sun conure',
|
| 64 |
+
'thick-billed parrot',
|
| 65 |
+
'turquoise-fronted amazon',
|
| 66 |
+
'vernal hanging parrot',
|
| 67 |
+
'white cockatoo',
|
| 68 |
+
'yellow-collared macaws',
|
| 69 |
+
'yellow-headed amazon']
|
| 70 |
+
|
| 71 |
+
def recognize_image(image):
|
| 72 |
+
pred, idx, probs = model.predict(image)
|
| 73 |
+
return dict(zip(parrot_species, map(float, probs)))
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
# im = "/content/drive/MyDrive/Learnings/fai/test_images/unknown_12.jpg"
|
| 77 |
+
# img = PILImage.create(im)
|
| 78 |
+
# img.thumbnail((192,192))
|
| 79 |
+
# img
|
| 80 |
+
|
| 81 |
+
# recognize_image(img)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
image = gr.inputs.Image(shape=(192,192))
|
| 86 |
+
label = gr.outputs.Label()
|
| 87 |
|
| 88 |
+
examples = [
|
| 89 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_00.jpg",
|
| 90 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_01.jpg",
|
| 91 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_02.jpg",
|
| 92 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_03.jpg",
|
| 93 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_04.jpg",
|
| 94 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_05.jpg",
|
| 95 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_06.jpg",
|
| 96 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_07.jpg",
|
| 97 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_08.jpg",
|
| 98 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_09.jpg",
|
| 99 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_10.jpg",
|
| 100 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_11.jpg",
|
| 101 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_12.jpg",
|
| 102 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_13.jpg",
|
| 103 |
+
"/content/drive/MyDrive/Learnings/fai/test_images/unknown_14.jpg",
|
| 104 |
+
]
|
| 105 |
|
| 106 |
+
iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
|
| 107 |
+
iface.launch(inline=False, share = True)
|