import numpy as np import pandas as pd import tensorflow as tf import streamlit as st from PIL import Image model = tf.keras.models.load_model(r"C:\Dhruv\potato diseases\my_model2.h5") resize_and_rescale = tf.keras.Sequential([ tf.keras.layers.experimental.preprocessing.Resizing(256,256), tf.keras.layers.experimental.preprocessing.Rescaling(1.0/255) ]) def predict(model, img): class_names = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy'] img_array = tf.keras.preprocessing.image.img_to_array(np.array(img)) img_array = tf.expand_dims(img_array, 0) img_array = resize_and_rescale(img_array) predictions = model.predict(img_array) predicted_class = class_names[np.argmax(predictions[0])] confidence = round(100 * (np.max(predictions[0])), 2) return predicted_class, confidence st.title("Potato Disease Classification") uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) if uploaded_image: st.image(uploaded_image) img = Image.open(uploaded_image) predicted_class, confidence = predict(model=model, img=img) st.markdown(f"The predicted class is **{predicted_class}** with **{confidence}%** confidence")