|
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): |
|
|
|
|
|
model=load_model('./cats&dog.h5') |
|
|
|
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) |
|
|
|
|
|
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() |