xr1nc3/catvsdogclassifier
0
1import streamlit as st
2import tensorflow as tf
3import numpy as np
4from PIL import Image
5from tensorflow.keras.applications.vgg16 import preprocess_input
6# use vgg19 if you trained with VGG19
7
8# Load model
9model = tf.keras.models.load_model("catdogmodel.keras")
10
11st.title("πΆπ± Dog vs Cat Classifier using VGG19")
12
13st.markdown(
14 "π **Click here to get dataset:** "
15 "[Dog vs Cat Dataset](https://drive.google.com/drive/folders/10B8a93wCFdkAQOZexofr79nPl4VQNHZ0?usp=sharing)"
16)
17
18uploaded_file = st.file_uploader(
19 "Upload a cat or dog image",
20 type=["jpg", "jpeg", "png"]
21)
22
23if uploaded_file:
24 image = Image.open(uploaded_file).convert("RGB")
25 st.image(image, use_column_width=True)
26
27 # MUST match training size
28 img = image.resize((224, 224))
29
30 img_array = np.array(img, dtype=np.float32)
31 img_array = preprocess_input(img_array) # π₯ CRITICAL
32 img_array = np.expand_dims(img_array, axis=0)
33
34 prediction = model.predict(img_array, verbose=0)[0][0]
35
36
37 if prediction >= 0.5:
38 st.success("Prediction: πΆ Dog")
39 else:
40 st.success("Prediction: π± Cat")
41
42 