Upload 2 files
Browse files- potato_model.h5 +3 -0
- streamlit_app.py +52 -0
potato_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b731b8339c7f93ee95c941b95cca2bb042c0cb608bba1d0b56e06649d14a6197
|
3 |
+
size 2288552
|
streamlit_app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import numpy as np
|
4 |
+
import tensorflow as tf
|
5 |
+
from werkzeug.utils import secure_filename
|
6 |
+
import os
|
7 |
+
|
8 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
9 |
+
|
10 |
+
class_names = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
|
11 |
+
|
12 |
+
def predict(model, img):
|
13 |
+
img_array = tf.keras.preprocessing.image.img_to_array(img)
|
14 |
+
img_array = tf.expand_dims(img_array, 0)
|
15 |
+
predictions = model.predict(img_array)
|
16 |
+
predictions_arr = [round(100 * i, 2) for i in predictions[0]]
|
17 |
+
predicted_class = class_names[np.argmax(predictions[0])]
|
18 |
+
confidence = round(100 * (np.max(predictions[0])), 2)
|
19 |
+
return predicted_class, predictions_arr
|
20 |
+
|
21 |
+
model = tf.keras.models.load_model('potato_model.h5', compile=False)
|
22 |
+
|
23 |
+
def main():
|
24 |
+
st.set_page_config(page_title="Potato Disease Classifier")
|
25 |
+
st.sidebar.title("Potato Disease Classifier")
|
26 |
+
st.sidebar.info("Upload an image of a potato leaf to detect early or late blight.")
|
27 |
+
st.title("Potato Disease Detection")
|
28 |
+
uploaded_file = st.file_uploader("Upload a potato leaf image",type=['jpg','png','jpeg'])
|
29 |
+
if uploaded_file is not None:
|
30 |
+
image = Image.open(uploaded_file)
|
31 |
+
st.image(image,caption="Uploaded Image",use_column_width=True)
|
32 |
+
image = image.resize((256,256))
|
33 |
+
img_arr = np.array(image)
|
34 |
+
predicted_class,predictions=predict(model,img_arr)
|
35 |
+
|
36 |
+
response = {
|
37 |
+
"predicted_class": predicted_class,
|
38 |
+
"early": f"{predictions[0]:.2f}%",
|
39 |
+
"late": f"{predictions[1]:.2f}%",
|
40 |
+
"healthy": f"{predictions[2]:.2f}%"
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
st.success(f"Predicted Class : {response['predicted_class']}",icon="✅")
|
45 |
+
st.write("Probabilities:")
|
46 |
+
col1,col2,col3 = st.columns(3)
|
47 |
+
col1.metric("Early Blight" , f"{response['early']}", f"{response['early']}")
|
48 |
+
col2.metric("Late Blight" , f"{response['late']}", f"{response['late']}")
|
49 |
+
col3.metric("Healthy" , f"{response['healthy']}", f"{response['healthy']}")
|
50 |
+
|
51 |
+
if __name__ == "__main__":
|
52 |
+
main()
|