import streamlit as st from tensorflow.keras.models import load_model from PIL import Image import os from huggingface_hub import notebook_login from huggingface_hub import hf_hub_download # Title of the Streamlit app st.title("Yellow Rust Severity Prediction") authkey= os.getenv('YellowRust') from huggingface_hub import login login(token=authkey) # Download the model file from Hugging Face model_path = hf_hub_download(repo_id="shaheer-data/Yellow-Rust-Prediction", filename="final_meta_model.keras") loaded_model = load_model(model_path) # Load model using tf.keras directly # Function to make predictions def predict_image(image): image = image.resize((224, 224)) # Resize to match model input dimensions image_array = tf.keras.preprocessing.image.img_to_array(image) image_array = tf.expand_dims(image_array, axis=0) # Expand dimensions for batch prediction predictions = loaded_model.predict(image_array) return predictions # Class labels for Yellow Rust severity levels CLASS_LABELS = [ "Healthy", "Mild Severity", "Moderate Severity", "Severe Severity", "Very Severe", "Extreme Severity" ] # Image upload widget uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) if uploaded_file is not None: image = Image.open(uploaded_file) st.image(image, caption="Uploaded Image", use_column_width=True) # Display progress bar with st.spinner("Making predictions..."): predictions = predict_image(image) predicted_class = predictions.argmax(axis=-1) st.write(f"Predicted Severity Level: {CLASS_LABELS[predicted_class[0]]} with confidence {predictions[0][predicted_class[0]]:.2f}") else: st.write("Please upload an image file to make predictions.")