Spaces:
Sleeping
Sleeping
shaheer-data
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -29,46 +29,58 @@ def preprocess_image(image):
|
|
29 |
return image
|
30 |
|
31 |
# Streamlit file uploader
|
32 |
-
uploaded_file = st.
|
33 |
|
34 |
if uploaded_file is not None:
|
35 |
-
st.
|
36 |
image = Image.open(uploaded_file)
|
37 |
-
st.
|
38 |
|
39 |
# Preprocess the image
|
40 |
processed_image = preprocess_image(image)
|
41 |
|
42 |
-
st.subheader("Prediction: With 97% Accuracy")
|
43 |
# Perform prediction
|
44 |
with st.spinner("Predicting..."):
|
45 |
prediction = loaded_model.predict(processed_image)
|
46 |
predicted_class = np.argmax(prediction, axis=1)[0] # Get the class index
|
47 |
-
class_labels = ['
|
48 |
-
|
49 |
st.header("Predicted Severity Class")
|
50 |
|
|
|
51 |
if predicted_class == 0:
|
52 |
-
st.markdown('<p style="color:
|
53 |
st.write("The leaf appears healthy. There is no immediate action required. Continue monitoring as needed.")
|
54 |
elif predicted_class == 1:
|
55 |
-
st.markdown('<p style="color:
|
56 |
-
st.write("Mild rust detected.
|
|
|
|
|
57 |
elif predicted_class == 2:
|
58 |
-
st.markdown('<p style="color: #
|
59 |
-
st.write("Moderate rust detected.
|
|
|
|
|
60 |
elif predicted_class == 3:
|
61 |
-
st.markdown('<p style="color: #FF4500; font-size:
|
62 |
-
st.write("Severe rust detected.
|
|
|
|
|
63 |
elif predicted_class == 4:
|
64 |
-
st.markdown('<p style="color:
|
65 |
-
st.write("Very severe rust detected.
|
|
|
|
|
|
|
66 |
elif predicted_class == 5:
|
67 |
-
st.markdown('<p style="color:
|
68 |
-
st.write("Extremely severe rust detected.
|
69 |
-
|
|
|
|
|
|
|
70 |
confidence = np.max(prediction) * 100
|
71 |
-
st.
|
72 |
|
73 |
# Footer
|
74 |
st.info("MPHIL Final Year Project By Mr. Asim Khattak")
|
|
|
29 |
return image
|
30 |
|
31 |
# Streamlit file uploader
|
32 |
+
uploaded_file = st.file_uploader("Upload a wheat leaf image", type=["jpg", "jpeg", "png"])
|
33 |
|
34 |
if uploaded_file is not None:
|
35 |
+
st.subheader("Uploaded Image")
|
36 |
image = Image.open(uploaded_file)
|
37 |
+
st.image(image, caption="Uploaded Image", use_container_width=True, width=500)
|
38 |
|
39 |
# Preprocess the image
|
40 |
processed_image = preprocess_image(image)
|
41 |
|
|
|
42 |
# Perform prediction
|
43 |
with st.spinner("Predicting..."):
|
44 |
prediction = loaded_model.predict(processed_image)
|
45 |
predicted_class = np.argmax(prediction, axis=1)[0] # Get the class index
|
46 |
+
class_labels = ['Healthy', 'Mild Rust (MR)', 'Moderate Rust (MRMS)', 'Severe Rust (MS)', 'Very Severe Rust (R)', 'Extremely Severe Rust (S)']
|
47 |
+
|
48 |
st.header("Predicted Severity Class")
|
49 |
|
50 |
+
# Colorful headings and styled responses
|
51 |
if predicted_class == 0:
|
52 |
+
st.markdown('<p style="color: #28a745; font-size: 22px; font-weight: bold;">Healthy</p>', unsafe_allow_html=True)
|
53 |
st.write("The leaf appears healthy. There is no immediate action required. Continue monitoring as needed.")
|
54 |
elif predicted_class == 1:
|
55 |
+
st.markdown('<p style="color: #FFA500; font-size: 22px; font-weight: bold;">Mild Rust (MR)</p>', unsafe_allow_html=True)
|
56 |
+
st.write("Mild rust detected.")
|
57 |
+
st.write("1. Apply fungicides to control rust growth.")
|
58 |
+
st.write("2. Regularly monitor the leaf for further signs of infection.")
|
59 |
elif predicted_class == 2:
|
60 |
+
st.markdown('<p style="color: #FF6347; font-size: 22px; font-weight: bold;">Moderate Rust (MRMS)</p>', unsafe_allow_html=True)
|
61 |
+
st.write("Moderate rust detected.")
|
62 |
+
st.write("1. Continue monitoring the leaf for any progression.")
|
63 |
+
st.write("2. Treat with fungicides as required.")
|
64 |
elif predicted_class == 3:
|
65 |
+
st.markdown('<p style="color: #FF4500; font-size: 22px; font-weight: bold;">Severe Rust (MS)</p>', unsafe_allow_html=True)
|
66 |
+
st.write("Severe rust detected.")
|
67 |
+
st.write("1. Apply fungicides promptly to control rust spread.")
|
68 |
+
st.write("2. Ensure regular monitoring to prevent further spread.")
|
69 |
elif predicted_class == 4:
|
70 |
+
st.markdown('<p style="color: #dc3545; font-size: 22px; font-weight: bold;">Very Severe Rust (R)</p>', unsafe_allow_html=True)
|
71 |
+
st.write("Very severe rust detected.")
|
72 |
+
st.write("1. Implement intensive control measures.")
|
73 |
+
st.write("2. Apply fungicides multiple times.")
|
74 |
+
st.write("3. Frequent monitoring is essential.")
|
75 |
elif predicted_class == 5:
|
76 |
+
st.markdown('<p style="color: #8B0000; font-size: 22px; font-weight: bold;">Extremely Severe Rust (S)</p>', unsafe_allow_html=True)
|
77 |
+
st.write("Extremely severe rust detected.")
|
78 |
+
st.write("1. Apply aggressive control strategies.")
|
79 |
+
st.write("2. Seek expert advice for advanced interventions.")
|
80 |
+
st.write("3. Frequent, close monitoring is critical.")
|
81 |
+
|
82 |
confidence = np.max(prediction) * 100
|
83 |
+
st.markdown(f'<p style="color: #17a2b8; font-size: 18px;">**Confidence Level:** {confidence:.2f}%</p>', unsafe_allow_html=True)
|
84 |
|
85 |
# Footer
|
86 |
st.info("MPHIL Final Year Project By Mr. Asim Khattak")
|