|
import streamlit as st |
|
from tensorflow.keras.models import load_model |
|
from tensorflow.keras.preprocessing.image import load_img, img_to_array |
|
import numpy as np |
|
import pickle |
|
|
|
|
|
model = load_model("best_model.h5") |
|
|
|
|
|
with open("mod_class_labels.pkl", "rb") as f: |
|
class_indices = pickle.load(f) |
|
|
|
|
|
def preprocess_image(image): |
|
image = load_img(image, target_size=(256, 256)) |
|
image = img_to_array(image) |
|
image = np.expand_dims(image, axis=0) |
|
image = image / 255.0 |
|
return image |
|
|
|
|
|
def predict_image(image): |
|
image = preprocess_image(image) |
|
prediction = model.predict(image) |
|
predicted_class = np.argmax(prediction, axis=1)[0] |
|
predicted_label = class_indices[predicted_class] |
|
return predicted_label |
|
|
|
|
|
st.title("Rice Leaf Disease Classification") |
|
|
|
st.write("Upload an image of a rice leaf and the model will predict its disease category.") |
|
|
|
|
|
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) |
|
|
|
if uploaded_file is not None: |
|
|
|
image = load_img(uploaded_file, target_size=(256, 256)) |
|
st.image(image, caption='Uploaded Image', use_column_width=True) |
|
st.write("") |
|
st.write("Classifying...") |
|
|
|
|
|
predicted_label = predict_image(uploaded_file) |
|
st.write(f"Predicted label: {predicted_label}") |
|
|