File size: 839 Bytes
fe34d3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import tensorflow as tf
from PIL import Image
import numpy as np

model = tf.keras.models.load_model('animal_classifier_model.h5')

class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']

st.title('Animal Classifier')

uploaded_file = st.file_uploader("Choose an image...", type="jpg")

if uploaded_file is not None:
    image = Image.open(uploaded_file)
    st.image(image, caption='Uploaded Image', use_column_width=True)

    image = image.resize((32, 32))
    image_array = np.array(image) / 255.0  
    image_array = np.expand_dims(image_array, axis=0)  

    predictions = model.predict(image_array)
    score = tf.nn.softmax(predictions[0])

    st.write(f"Prediction: {class_names[np.argmax(score)]}")
    st.write(f"Confidence: {100 * np.max(score):.2f}%")