Defkhan5960's picture
Upload 3 files
5311003 verified
raw
history blame contribute delete
No virus
1.47 kB
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}")