File size: 3,824 Bytes
7a7f340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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 = """
            <style>
            #MainMenu {visibility: hidden;}
            footer {visibility: hidden;}
            </style>
            """
            
st.markdown(hide_streamlit_style, unsafe_allow_html = True)

st.title('Plant Disease Prediction')
st.write("This model is capable of predicting 38 different classes of plant diseases")

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'final1_model.h5', compile = False)

    shape = ((255,255,3))
    model = keras.Sequential([hub.KerasLayer(classifier_model, input_shape = shape)])     # ye bhi kaam kar raha he
    test_image = image.resize((255, 255))
    test_image = keras.preprocessing.image.img_to_array(test_image)
    test_image /= 255.0
    test_image = np.expand_dims(test_image, axis = 0)
    class_name = ["Apple___Apple_scab","Apple___Black_rot",
              "Apple___Cedar_apple_rust","Apple___healthy",
              "Blueberry___healthy",
              "Cherry_(including_sour)___Powdery_mildew",
              "Cherry___healthy",
              "Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot", 
              "Corn_(maize)___Common_rust_",
              "Corn_(maize)___Northern_Leaf_Blight",
              "Corn_(maize)___healthy","Grape___Black_rot",
              "Grape___Esca_(Black_Measles)",
              "Grape___Leaf_blight_(Isariopsis_Leaf_Spot)",
              "Grape___healthy",
              "Orange___Haunglongbing_(Citrus_greening)",
              "Peach___Bacterial_spot",
              "Peach___healthy",
              "Pepper__bell___Bacterial_spot",
              "Pepper,_bell___healthy",
              "Potato___Early_blight",
              "Potato___Late_blight",
              "Potato___healthy",
              "Raspberry___healthy",
              "Soybean___healthy",
              "Squash___Powdery_mildew",
              "Strawberry___Leaf_scorch",
              "Strawberry___healthy",
              "Tomato___Bacterial_spot",
              "Tomato___Early_blight",
              "Tomato___Late_blight",
              "Tomato___Leaf_Mold",
              "Tomato___Septoria_leaf_spot",
              "Tomato___Spider_mites Two-spotted_spider_mite",
              "Tomato___Target_Spot",
              "Tomato___Tomato_Yellow_Leaf_Curl_Virus",
              "Tomato___Tomato_mosaic_virus",
              "Tomato___healthy"]
    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 = """
<style>
a:link , a:visited{
    color: white;
    background-color: transparent;
    text-decoration: None;
}

a:hover,  a:active {
    color: red;
    background-color: transparent;
    text-decoration: None;
}

.footer {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    background-color: transparent;
    color: black;
    text-align: center;
}

<div class="footer">
<p align="center"> Developed with ❤ by Mato</p>
</div>
</style>
"""
st.markdown(footer, unsafe_allow_html = True) 
if __name__ == "__main__": 
    main()