import streamlit as st import numpy as np import pickle import cv2 from PIL import Image # Load model and label binarizer @st.cache_resource def load_model(): model = pickle.load(open('cnn_model.pkl', 'rb')) label_binarizer = pickle.load(open('label_transform.pkl', 'rb')) return model, label_binarizer model, lb = load_model() # Prediction function def predict(image): image = cv2.resize(image, (256, 256)) image = image.astype("float") / 255.0 image = np.expand_dims(image, axis=0) preds = model.predict(image) return lb.classes_[np.argmax(preds)] # Streamlit UI st.title("🌱 Plant Disease Detector") uploaded_file = st.file_uploader("Upload a leaf image...", type=["jpg", "png"]) if uploaded_file is not None: image = Image.open(uploaded_file).convert("RGB") st.image(image, caption="Uploaded Image", use_column_width=True) if st.button("Predict"): img_array = np.array(image) img_array = cv2.cvtColor(img_array, cv2.COLOR_RGB2BGR) prediction = predict(img_array) st.success(f"🔍 Prediction: {prediction}")