import streamlit as st from PIL import Image import numpy as np import tensorflow as tf from tensorflow import keras import matplotlib.pyplot as plt import tensorflow_hub as hub hide_streamlit_style = """ """ st.markdown(hide_streamlit_style, unsafe_allow_html = True) st.title('Plant Disease Prediction') st.write("This model is capable of predicting plant disease as a demo") def main() : file_uploaded = st.file_uploader('Choose an image...', type = 'jpg') if file_uploaded is not None : image = Image.open(file_uploaded) st.write("Uploaded Image.") figure = plt.figure() plt.imshow(image) plt.axis('off') st.pyplot(figure) result, confidence = predict_class(image) st.write('Prediction : {}'.format(result)) st.write('Confidence : {}%'.format(confidence)) def predict_class(image) : with st.spinner('Loading Model...'): classifier_model = keras.models.load_model(r'plant_badr_model.h5', compile = False) shape = ((200,200,3)) model = keras.Sequential([hub.KerasLayer(classifier_model, input_shape = shape)]) # ye bhi kaam kar raha he test_image = image.resize((200, 200)) test_image = keras.preprocessing.image.img_to_array(test_image) test_image /= 256.0 test_image = np.expand_dims(test_image, axis = 0) class_name = list(range(0, 37)) prediction = model.predict_generator(test_image) confidence = round(100 * (np.max(prediction[0])), 2) final_pred = class_name[np.argmax(prediction)] return final_pred, confidence footer = """ """ st.markdown(footer, unsafe_allow_html = True) if __name__ == "__main__": main()