File size: 1,026 Bytes
1a5d306
 
 
 
8339622
1a5d306
6d90b91
1a5d306
 
6d90b91
 
 
 
 
 
 
 
 
 
efbf2a8
0d19427
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr
import tensorflow as tf
import numpy as np

model = tf.keras.models.load_model('bird_modelV2.h5')

label = ['Asian-Green-Bee-Eater', 'Brown-Headed-Barbet', 'Cattle-Egret', 'Common-Kingfisher', 'Common-Myna', 'Common-Rosefinch', 'Common-Tailorbird', 'Coppersmith-Barbet', 'Forest-Wagtail', 'Gray-Wagtail', 'Hoopoe', 'House-Crow', 'Indian-Grey-Hornbill', 'Indian-Peacock', 'Indian-Pitta', 'Indian-Roller', 'Jungle-Babbler', 'Northern-Lapwing', 'Red-Wattled-Lapwing', 'Ruddy-Shelduck', 'Rufous-Treepie', 'Sarus-Crane', 'White-Breasted-Kingfisher', 'White-Breasted-Waterhen', 'White-Wagtail']

def image_classifier(inp):
    img = tf.image.resize(inp, (224, 224))
    img = tf.keras.preprocessing.image.img_to_array(img)
    img = np.expand_dims(img, axis=0)
    
    predictions = model.predict(img)[0]
    
    return {label[i]: float(predictions[i]) for i in range(25)}
    
   

demo = gr.Interface(fn=image_classifier, inputs='image',outputs=gr.Label(num_top_classes=5))
demo.launch(debug=True,share=true)