from keras.models import load_model import numpy as np from keras.preprocessing import image import gradio as gr from PIL import Image model=load_model('./flower.h5') def show(img): img = img.reshape( 180, 180,3) test_image=np.expand_dims(img, axis=0) prediction=model.predict(test_image).tolist()[0] class_names = ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips'] return {class_names[i]: prediction[i] for i in range(5)} image = gr.inputs.Image(shape=(180,180)) demo = gr.Interface( fn = show, inputs = image, examples=["photo/a01.jpg", "photo/a02.jpg","photo/a03.jpg","photo/a04.jpg","photo/a05.jpg"], title="Flower Image Classification", outputs = gr.outputs.Label(), ) if __name__ == "__main__": demo.launch()