|
|
|
|
|
|
|
import streamlit as st |
|
import tensorflow as tf |
|
import numpy as np |
|
from PIL import Image |
|
import io |
|
|
|
class CoffeeLandClassifier: |
|
def __init__(self, model_path, class_labels): |
|
self.model = tf.keras.models.load_model(model_path) |
|
self.class_labels = class_labels |
|
|
|
def run(self): |
|
st.title("Coffee Land Classifier") |
|
|
|
|
|
uploaded_image = st.file_uploader("Please upload an image", type=["jpg", "jpeg", "png"]) |
|
|
|
if uploaded_image is not None: |
|
|
|
img = Image.open(uploaded_image) |
|
img = img.resize((64, 64)) |
|
img = np.array(img) |
|
img = img.astype('float32') / 255.0 |
|
img = np.expand_dims(img, axis=0) |
|
|
|
|
|
predictions = self.model.predict(img) |
|
class_index = np.argmax(predictions) |
|
predicted_class = self.class_labels[class_index] |
|
|
|
|
|
st.image(img[0]) |
|
|
|
|
|
st.write(f"Prediction: {predicted_class}") |
|
st.write("Class Probabilities:") |
|
for i, prob in enumerate(predictions[0]): |
|
st.write(f"{self.class_labels[i]}: {prob * 100:.2f}%") |
|
|
|
def main(): |
|
model_path = "model/model.h5" |
|
class_labels = ["Coffee Land", "Not Coffee Land"] |
|
classifier = CoffeeLandClassifier(model_path, class_labels) |
|
classifier.run() |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|