| import gradio as gr | |
| from PIL import Image | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import tensorflow as tf | |
| from tensorflow.keras import layers | |
| from tensorflow.keras.models import Sequential | |
| from tensorflow.keras.models import load_model | |
| from keras.preprocessing import image | |
| model3 = load_model('best_beans.h5') | |
| leaf_class=['angular_leaf_spot', 'bean_rust', 'healthy'] | |
| def classify_image(img): | |
| img_width, img_height = 224, 224 | |
| img = image.load_img(img, target_size = (img_width, img_height)) | |
| img = image.img_to_array(img) | |
| img = np.expand_dims(img, axis = 0) | |
| prediction = model3.predict(img)[0] | |
| return {leaf_class[i]: float(prediction[i]) for i in range(3)} | |
| gr.Interface(fn=classify_image, | |
| inputs=gr.Image( type ="filepath"), | |
| outputs=gr.Label(num_top_classes=1)).launch(debug=True) |