xcurvnubaim
commited on
Commit
·
feeed5b
1
Parent(s):
772a5bb
feat: gradio
Browse files- app.py +33 -0
- labels.txt +90 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from tensorflow.keras.models import load_model
|
2 |
+
import numpy as np
|
3 |
+
import gradio as gr
|
4 |
+
import tensorflow as tf
|
5 |
+
from io import StringIO
|
6 |
+
from PIL import Image
|
7 |
+
import requests
|
8 |
+
|
9 |
+
url = "https://drive.usercontent.google.com/download?id=1T5HGnk9Mxlb5G6FTxp26BWSrTpzbjtP2&export=download&authuser=0"
|
10 |
+
open("models.h5", "wb").write(requests.get(url).content)
|
11 |
+
labels = []
|
12 |
+
model = load_model('/content/models.h5')
|
13 |
+
with open("/content/name of the animals.txt") as f:
|
14 |
+
for line in f:
|
15 |
+
labels.append(line.replace('\n', ''))
|
16 |
+
|
17 |
+
def classify_image(inp):
|
18 |
+
# Create a copy of the input array to avoid reference issues
|
19 |
+
inp_copy = np.copy(inp)
|
20 |
+
# Resize the input image to the expected shape (224, 224)
|
21 |
+
inp_copy = Image.fromarray(inp_copy)
|
22 |
+
inp_copy = inp_copy.resize((224, 224))
|
23 |
+
inp_copy = np.array(inp_copy)
|
24 |
+
inp_copy = inp_copy.reshape((-1, 224, 224, 3))
|
25 |
+
inp_copy = tf.keras.applications.efficientnet.preprocess_input(inp_copy)
|
26 |
+
prediction = model.predict(inp_copy).flatten()
|
27 |
+
confidences = {labels[i]: float(prediction[i]) for i in range(90)}
|
28 |
+
return confidences
|
29 |
+
|
30 |
+
demo = gr.Interface(classify_image, gr.Image(), gr.Label(num_top_classes=3))
|
31 |
+
if __name__ == "__main__":
|
32 |
+
demo.launch()
|
33 |
+
|
labels.txt
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
antelope
|
2 |
+
badger
|
3 |
+
bat
|
4 |
+
bear
|
5 |
+
bee
|
6 |
+
beetle
|
7 |
+
bison
|
8 |
+
boar
|
9 |
+
butterfly
|
10 |
+
cat
|
11 |
+
caterpillar
|
12 |
+
chimpanzee
|
13 |
+
cockroach
|
14 |
+
cow
|
15 |
+
coyote
|
16 |
+
crab
|
17 |
+
crow
|
18 |
+
deer
|
19 |
+
dog
|
20 |
+
dolphin
|
21 |
+
donkey
|
22 |
+
dragonfly
|
23 |
+
duck
|
24 |
+
eagle
|
25 |
+
elephant
|
26 |
+
flamingo
|
27 |
+
fly
|
28 |
+
fox
|
29 |
+
goat
|
30 |
+
goldfish
|
31 |
+
goose
|
32 |
+
gorilla
|
33 |
+
grasshopper
|
34 |
+
hamster
|
35 |
+
hare
|
36 |
+
hedgehog
|
37 |
+
hippopotamus
|
38 |
+
hornbill
|
39 |
+
horse
|
40 |
+
hummingbird
|
41 |
+
hyena
|
42 |
+
jellyfish
|
43 |
+
kangaroo
|
44 |
+
koala
|
45 |
+
ladybugs
|
46 |
+
leopard
|
47 |
+
lion
|
48 |
+
lizard
|
49 |
+
lobster
|
50 |
+
mosquito
|
51 |
+
moth
|
52 |
+
mouse
|
53 |
+
octopus
|
54 |
+
okapi
|
55 |
+
orangutan
|
56 |
+
otter
|
57 |
+
owl
|
58 |
+
ox
|
59 |
+
oyster
|
60 |
+
panda
|
61 |
+
parrot
|
62 |
+
pelecaniformes
|
63 |
+
penguin
|
64 |
+
pig
|
65 |
+
pigeon
|
66 |
+
porcupine
|
67 |
+
possum
|
68 |
+
raccoon
|
69 |
+
rat
|
70 |
+
reindeer
|
71 |
+
rhinoceros
|
72 |
+
sandpiper
|
73 |
+
seahorse
|
74 |
+
seal
|
75 |
+
shark
|
76 |
+
sheep
|
77 |
+
snake
|
78 |
+
sparrow
|
79 |
+
squid
|
80 |
+
squirrel
|
81 |
+
starfish
|
82 |
+
swan
|
83 |
+
tiger
|
84 |
+
turkey
|
85 |
+
turtle
|
86 |
+
whale
|
87 |
+
wolf
|
88 |
+
wombat
|
89 |
+
woodpecker
|
90 |
+
zebra
|