File size: 1,525 Bytes
08215ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
import streamlit as st
import tensorflow as tf
import cv2
import numpy as np

def run():
    # Load the saved model
    model = tf.keras.models.load_model("best_model.h5")

    # Define the label names
    label_names = ['a', 'b', 'c', 'd', 'e', 'del', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'not', 'o',
            'p', 'q', 'r', 's', 't', 'space', 'u', 'v', 'w', 'x', 'y', 'z']

    # Define the Streamlit app
    st.title("ASL image Prediction")
    st.write("Choose an image to classify.")

    # Allow the user to select an image file
    uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])

    if uploaded_file is not None:
        # Load the image using TensorFlow
        img = tf.keras.utils.load_img(uploaded_file, target_size=(150, 150, 3))

        # Convert the PIL.Image.Image object to a NumPy array
        x = tf.keras.utils.img_to_array(img)

        # Expand the array to add a batch dimension
        x = np.expand_dims(x, axis=0)

        # Normalize the image data
        x = x / 255.0

        # Make the prediction using the loaded model
        y_pred = model.predict(x)

        # Get the index of the predicted class with the highest probability
        class_idx = np.argmax(y_pred, axis=1)[0]

        # Display the predicted class label and image to the user
        st.write(f"Detection for uploaded image: {label_names[class_idx]}")
        st.image(img, caption=f"{label_names[class_idx]}", use_column_width=True)


if __name__=="__main__":
    run()