Download app.py from Fluospark128/Cassava_Disease_Classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/Fluospark128/Cassava_Disease_Classifier/resolve/main/app.py
- Command line
-
hf download hf://spaces/Fluospark128/Cassava_Disease_Classifier/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Fluospark128/Cassava_Disease_Classifier/resolve/main/app.py
1.49 kB
| # Available backend options are: "jax", "torch", "tensorflow". | |
| import os | |
| #os.environ["KERAS_BACKEND"] = "tensorflow" | |
| #pip install -U keras huggingface_hub | |
| #import keras | |
| #model = keras.saving.load_model("hf://Fluospark128/Cassava_Disease_Classifier") | |
| import streamlit as st | |
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| # Load the model | |
| #@st.cache_resource | |
| def load_model(): | |
| model = tf.keras.models.load_model("cassava_leaf_disease_model.keras") #tf.keras.saving.load_model("hf://Fluospark128/Cassava_Disease_Classifier") cassava_model.h5 | |
| return model | |
| model = load_model() | |
| # Class labels | |
| CLASS_NAMES = ["Cassava Bacterial Blight Disease", "Cassava Brown Streak Disease", "Cassava Green Mottle Disease", "Cassava Mosaic Disease", "Healthy"] | |
| # Streamlit UI | |
| st.title("Cassava Leaf Disease Identifier") | |
| st.write("Upload an image of a cassava leaf to identify its disease.") | |
| # File uploader | |
| uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"]) | |
| if uploaded_file is not None: | |
| image = Image.open(uploaded_file).resize((224, 224)) | |
| st.image(image, caption="Uploaded Image", use_container_width=True) | |
| # Preprocess image | |
| img_array = np.array(image) / 255.0 # Normalize | |
| img_array = np.expand_dims(img_array, axis=0) # Add batch dimension | |
| # Make prediction | |
| prediction = model.predict(img_array) | |
| predicted_class = CLASS_NAMES[np.argmax(prediction)] | |
| st.write(f"Prediction: **{predicted_class}**") | |