import streamlit as st import tensorflow as tf from tensorflow import keras from PIL import Image import numpy as np #model model = tf.keras.models.load_model(r'C:\Users\Souvik Chand\Documents\python_my\apps\stream lits\cats and dogs\model3.h5') labels = ['Cat', 'Dog'] def preprocess_image(image): """resizes the image""" image = image.resize((256, 256)) # Adjust based on your model's input size image = np.array(image) / 255.0 # Normalize the image image = np.expand_dims(image, axis=0) return image def process(image): """not in use""" image= tf.cast(image/255, tf.float32) return image st.title('Dogs and cats') st.write('Upload an image and the model will predict its class.') st.sidebar.title('upload a photo') uploaded_file = st.sidebar.file_uploader('choose image',accept_multiple_files=False, type=['jpg']) if uploaded_file is not None: image = Image.open(uploaded_file) st.image(image, caption='Uploaded Image', use_column_width=True,width=100) st.write(f'Original Image Shape: {image.size}') preprocessed_image = preprocess_image(image) test_input = preprocessed_image.reshape((1,256,256,3)) predictions = model.predict(test_input)[0][0] confidence= round((abs(predictions-0.5)/0.5)*100) st.write(predictions) if predictions<0.2: st.write(f'Predicted class: Cat') elif predictions>0.8: st.write('Prediction class: Dog') elif (predictions <0.7) or (predictions >0.6): st.write('i feel you are trying to trick me!') else: st.write("looks like neither") st.write(f'confidence: {confidence}%')