| import streamlit as st
|
| from tensorflow.keras.preprocessing import image
|
| import numpy as np
|
| from PIL import Image
|
| import tensorflow as tf
|
|
|
|
|
| @st.cache_resource
|
| def load_model():
|
| model = tf.keras.models.load_model('catdogmodel.h5')
|
| return model
|
|
|
| model = load_model()
|
|
|
|
|
| st.title("π±πΆ Cat vs. Dog Classifier")
|
|
|
|
|
| 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:
|
|
|
| img = Image.open(uploaded_file)
|
| st.image(img, caption='Uploaded Image', use_column_width=True)
|
| st.write("π **Analyzing 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
|
|
|
|
|
| prediction = model.predict(img_array)
|
|
|
|
|
| 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!")
|
|
|