File size: 1,360 Bytes
f757486
 
 
 
 
 
ed65443
 
42f61d9
f757486
ed65443
f757486
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import streamlit as st
import tensorflow as tf
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import img_to_array, load_img
import numpy as np



model = load_model("model_final_2.h5")
# Load the trained model


# Define the class names based on your dataset
class_names = ['Bacterial leaf blight', 'Brown spot', 'Healthy', 'Leaf Blast', 'Leaf scald', 'Narrow Brown Spot']

# Streamlit app
st.title("Rice Leaf Disease Detection")

# Image upload
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    # Load the image
    image = load_img(uploaded_file, target_size=(299, 299))

    # Display the image at 50% of the original size
    st.markdown(
        """
        <style>
        img {
            max-width: 50%;
            height: auto;
        }
        </style>
        """,
        unsafe_allow_html=True
    )
    st.image(image, caption='Uploaded Image', use_column_width=False)

    # Preprocess the image
    image = img_to_array(image)
    image = np.expand_dims(image, axis=0)
    image = image / 255.0

    # Make predictions
    predictions = model.predict(image)
    predicted_class = np.argmax(predictions, axis=1)
    predicted_class_name = class_names[predicted_class[0]]

    st.title(f"Detected Diseases: {predicted_class_name}")