Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,23 @@
|
|
1 |
-
import os
|
2 |
-
import numpy as np
|
3 |
import streamlit as st
|
4 |
-
from PIL import Image
|
5 |
from tensorflow.keras.models import load_model
|
6 |
-
from tensorflow.keras.preprocessing.image import img_to_array
|
7 |
-
from
|
8 |
-
|
|
|
|
|
9 |
|
10 |
# Title of the Streamlit app
|
11 |
st.title("Yellow Rust Severity Prediction")
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
login(token=authkey)
|
17 |
|
18 |
-
|
19 |
# Download the model file from Hugging Face
|
20 |
model_path = hf_hub_download(repo_id="shaheer-data/Yellow-Rust-Prediction", filename="final_meta_model.keras")
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
loaded_model = load_model(model_path) # Load model using tf.keras directly
|
25 |
|
26 |
# Function to preprocess the uploaded image
|
27 |
def preprocess_image(image):
|
@@ -36,7 +32,7 @@ def preprocess_image(image):
|
|
36 |
uploaded_file = st.file_uploader("Upload a wheat leaf image", type=["jpg", "jpeg", "png"])
|
37 |
|
38 |
if uploaded_file is not None:
|
39 |
-
|
40 |
image = Image.open(uploaded_file)
|
41 |
st.image(image, caption="Uploaded Image", use_container_width=True)
|
42 |
|
@@ -48,4 +44,28 @@ if uploaded_file is not None:
|
|
48 |
prediction = loaded_model.predict(processed_image)
|
49 |
predicted_class = np.argmax(prediction, axis=1)[0] # Get the class index
|
50 |
class_labels = ['0', 'MR', 'MRMS', 'MS', 'R', 'S'] # Update based on your classes
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from tensorflow.keras.models import load_model
|
3 |
+
from tensorflow.keras.preprocessing.image import img_to_array # Import this function
|
4 |
+
from PIL import Image
|
5 |
+
import numpy as np
|
6 |
+
import os
|
7 |
+
from huggingface_hub import hf_hub_download, login
|
8 |
|
9 |
# Title of the Streamlit app
|
10 |
st.title("Yellow Rust Severity Prediction")
|
11 |
|
12 |
+
# Authentication using Hugging Face token
|
13 |
+
authkey = os.getenv('YellowRust')
|
|
|
14 |
login(token=authkey)
|
15 |
|
|
|
16 |
# Download the model file from Hugging Face
|
17 |
model_path = hf_hub_download(repo_id="shaheer-data/Yellow-Rust-Prediction", filename="final_meta_model.keras")
|
18 |
|
19 |
+
# Load the pre-trained model
|
20 |
+
loaded_model = load_model(model_path)
|
|
|
21 |
|
22 |
# Function to preprocess the uploaded image
|
23 |
def preprocess_image(image):
|
|
|
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)
|
38 |
|
|
|
44 |
prediction = loaded_model.predict(processed_image)
|
45 |
predicted_class = np.argmax(prediction, axis=1)[0] # Get the class index
|
46 |
class_labels = ['0', 'MR', 'MRMS', 'MS', 'R', 'S'] # Update based on your classes
|
47 |
+
|
48 |
+
if predicted_class == 0:
|
49 |
+
st.write("Predicted Severity Class: Healthy")
|
50 |
+
st.write("**Advice:** The leaf appears healthy. Continue monitoring as needed.")
|
51 |
+
elif predicted_class == 1:
|
52 |
+
st.write("Predicted Severity Class: Mild Rust (MR)")
|
53 |
+
st.write("**Advice:** Apply fungicides to control mild rust development.")
|
54 |
+
elif predicted_class == 2:
|
55 |
+
st.write("Predicted Severity Class: Moderate Rust (MRMS)")
|
56 |
+
st.write("**Advice:** Monitor regularly and treat with appropriate fungicides.")
|
57 |
+
elif predicted_class == 3:
|
58 |
+
st.write("Predicted Severity Class: Severe Rust (MS)")
|
59 |
+
st.write("**Advice:** Apply fungicides promptly and continue monitoring.")
|
60 |
+
elif predicted_class == 4:
|
61 |
+
st.write("Predicted Severity Class: Very Severe Rust (R)")
|
62 |
+
st.write("**Advice:** Implement intensive control measures and frequent monitoring.")
|
63 |
+
elif predicted_class == 5:
|
64 |
+
st.write("Predicted Severity Class: Extremely Severe Rust (S)")
|
65 |
+
st.write("**Advice:** Apply aggressive control strategies and seek expert advice.")
|
66 |
+
|
67 |
+
confidence = np.max(prediction) * 100
|
68 |
+
st.write(f"**Confidence Level:** {confidence:.2f}%")
|
69 |
+
|
70 |
+
# Footer
|
71 |
+
st.sidebar.info("Powered by Streamlit and TensorFlow")
|