tree-test / app.py
willco-afk's picture
Update app.py
dae7f18 verified
raw
history blame
1.16 kB
import os
import streamlit as st
import tensorflow as tf
from PIL import Image
import numpy as np
# Load your Keras model from Google Drive
model = tf.keras.models.load_model('/content/drive/MyDrive/your_trained_model.keras')
# Streamlit UI
st.title("Christmas Tree Classifier")
st.write("Upload an image of a Christmas tree to classify it:")
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Display the uploaded image
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image.", use_column_width=True)
st.write("")
st.write("Classifying...")
# Preprocess the image
image = image.resize((224, 224)) # Resize to match your model's input size
image_array = np.array(image) / 255.0 # Normalize pixel values
image_array = np.expand_dims(image_array, axis=0) # Add batch dimension
# Make prediction
prediction = model.predict(image_array)
# Get predicted class
predicted_class = "Decorated" if prediction[0][0] >= 0.5 else "Undecorated"
# Display the prediction
st.write(f"Prediction: {predicted_class}")