Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
from PIL import Image, ImageDraw
|
| 5 |
+
|
| 6 |
+
# Load your trained meta-model
|
| 7 |
+
MODEL_PATH = "hf://shaheer-data/Yellow-Rust-Prediction/final_meta_model.keras" # Replace with your model path
|
| 8 |
+
model = tf.keras.models.load_model(MODEL_PATH)
|
| 9 |
+
|
| 10 |
+
# Set page configuration
|
| 11 |
+
st.set_page_config(page_title="Yellow Rust Disease Classification", layout="wide", initial_sidebar_state="expanded")
|
| 12 |
+
|
| 13 |
+
# Theme selection
|
| 14 |
+
st.sidebar.title("Settings and Preferences")
|
| 15 |
+
theme = st.sidebar.selectbox("Select Theme", ["Light", "Dark"])
|
| 16 |
+
if theme == "Dark":
|
| 17 |
+
st.markdown(
|
| 18 |
+
"<style>body { background-color: #0e1117; color: white; }</style>",
|
| 19 |
+
unsafe_allow_html=True,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Title
|
| 23 |
+
st.title("Yellow Rust Disease Classification Dashboard")
|
| 24 |
+
|
| 25 |
+
# User Input Section
|
| 26 |
+
st.sidebar.header("Upload Image of Plant Leaf")
|
| 27 |
+
image_file = st.sidebar.file_uploader("Upload an Image", type=["jpg", "png", "jpeg"])
|
| 28 |
+
|
| 29 |
+
if image_file:
|
| 30 |
+
st.subheader("Uploaded Image")
|
| 31 |
+
image = Image.open(image_file)
|
| 32 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 33 |
+
|
| 34 |
+
# Preprocess the image for prediction
|
| 35 |
+
def preprocess_image(img):
|
| 36 |
+
img = img.resize((224, 224)) # Adjust to model input size
|
| 37 |
+
img_array = np.array(img) / 255.0 # Normalize
|
| 38 |
+
return np.expand_dims(img_array, axis=0) # Add batch dimension
|
| 39 |
+
|
| 40 |
+
processed_image = preprocess_image(image)
|
| 41 |
+
|
| 42 |
+
# Prediction Results
|
| 43 |
+
predictions = model.predict(processed_image)
|
| 44 |
+
class_names = ["0", "MR", "MRMS", "MS", "R", "S"] # Replace with actual class labels from dataset
|
| 45 |
+
predicted_class = class_names[np.argmax(predictions)]
|
| 46 |
+
confidence = np.max(predictions) * 100
|
| 47 |
+
|
| 48 |
+
st.header("Prediction Results")
|
| 49 |
+
st.write(f"**Predicted Status:** {predicted_class}")
|
| 50 |
+
st.write(f"**Confidence Level:** {confidence:.2f}%")
|
| 51 |
+
|
| 52 |
+
# Severity Level
|
| 53 |
+
severity = "High" if confidence > 80 else "Moderate" if confidence > 50 else "Low"
|
| 54 |
+
st.write(f"**Severity Level:** {severity}")
|
| 55 |
+
|
| 56 |
+
# Highlighting a region (Example: bounding box)
|
| 57 |
+
st.subheader("Highlighted Regions")
|
| 58 |
+
draw = ImageDraw.Draw(image)
|
| 59 |
+
# Example bounding box coordinates, adjust as necessary
|
| 60 |
+
draw.rectangle([50, 50, 150, 150], outline="red", width=3) # Example bounding box
|
| 61 |
+
st.image(image, caption="Highlighted Regions", use_column_width=True)
|
| 62 |
+
|
| 63 |
+
# Disease Insights
|
| 64 |
+
st.header("Disease Insights")
|
| 65 |
+
for i, class_name in enumerate(class_names):
|
| 66 |
+
st.write(f"{class_name}: {predictions[0][i] * 100:.2f}%")
|
| 67 |
+
|
| 68 |
+
# Model Performance Metrics (Admin Only)
|
| 69 |
+
if st.checkbox("Show Model Performance Metrics (Admin Only)"):
|
| 70 |
+
st.write("**Accuracy:** 95.6%") # Replace with actual metric
|
| 71 |
+
st.write("**Precision:** 94.7%") # Replace with actual metric
|
| 72 |
+
st.write("**Recall:** 93.5%") # Replace with actual metric
|
| 73 |
+
|
| 74 |
+
# User Notifications
|
| 75 |
+
if severity == "High":
|
| 76 |
+
st.warning("High severity detected! Immediate action is recommended.")
|
| 77 |
+
|
| 78 |
+
# Footer
|
| 79 |
+
st.sidebar.info("Powered by Streamlit and TensorFlow")
|