File size: 1,236 Bytes
bcfc921
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from keras.models import load_model
import numpy as np
from keras.preprocessing import image
import gradio as gr
from PIL import Image

def a(img):
    #img = img.reshape(1, 64, 64,3)
    #img = img.reshape( 64, 64,3)
    model=load_model('./cats&dog.h5')
    #test_image=image.load_img("pic01.jpg",target_size=(64,64))
    test_image=image.img_to_array(img)
    test_image=np.expand_dims(test_image, axis=0)    
    result=model.predict(test_image)
    if result[0][0]==1:
        prediction='Dog'
        print(prediction)
        return prediction
    else:
        prediction='Cat'
        print(prediction)
        return prediction
 

input = gr.inputs.Image(type='pil', label="Original Image", source="upload", optional=True)
#input_2 = gr.inputs.Image(type='pil', label="Original Image", source="webcam", optional=True)
#inputs = [input, input_2]
inputs = [input]
outputs = gr.outputs.Image(type="pil", label="Output Image")
title = "Dog and Cat Object detection"

demo=gr.Interface(a,
             inputs, 
             outputs, 
             title=title,
             examples=["a01.jpg", "a02.jpg","a03.jpg","a04.jpg"],
             theme="huggingface").launch(enable_queue=True)

if __name__ == "__main__":
    demo.launch()