File size: 1,200 Bytes
a4ebc5d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import streamlit as st
from tensorflow.keras.preprocessing import image
import numpy as np
from PIL import Image
import tensorflow as tf
# Load the model
@st.cache_resource
def load_model():
model = tf.keras.models.load_model('catdogmodel.h5') # Path to your model
return model
model = load_model()
# Title
st.title("π±πΆ Cat vs. Dog Classifier")
# Image Upload
st.header("Upload an Image")
uploaded_file = st.file_uploader("Please upload a cat or dog image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Open and display the image
img = Image.open(uploaded_file)
st.image(img, caption='Uploaded Image', use_column_width=True)
st.write("π **Analyzing the image...**")
# Preprocess the image
img = img.resize((128, 128))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array /= 255.0
# Predict
prediction = model.predict(img_array)
# Display the result
if prediction < 0.5:
st.write("πΆ **It's a Dog!**")
else:
st.write("π± **It's a Cat!**")
else:
st.write("π Upload an image to get started!")
|