File size: 1,466 Bytes
5311003
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from PIL import Image
import numpy as np
import tensorflow as tf
from keras.preprocessing.image import img_to_array

# Load the pre-trained model
model = tf.keras.models.load_model("student.h5")

# Define the class names
class_names = ["Diger", "MuhammetAliSimsek", "MuserrefSelcukOzdemir", "ZekeriyyaKoroglu"]

# Function to preprocess the image for model prediction
def preprocess_image(image_path):
    img = Image.open(image_path).convert("RGB")
    img = img.resize((224, 224))  # Ensure the image size matches the model input size
    img_array = img_to_array(img)
    img_array = np.expand_dims(img_array, axis=0)
    return img_array  # Normalize the pixel values

# Streamlit App
st.title("Student Recognition App")

# Upload image through Streamlit
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    # Display the uploaded image
    st.image(uploaded_file, caption="Uploaded Image.", use_column_width=True)

    # Preprocess the uploaded image
    input_image = preprocess_image(uploaded_file)

    # Make prediction using the model
    predictions = model.predict(input_image)

    # Get the predicted class
    predicted_class_index = np.argmax(predictions)
    predicted_class = class_names[predicted_class_index]

    # Display the prediction result
    st.write("Prediction Result:")
    st.write(f"The person in the image is predicted as: {predicted_class}")