vargar/Non_binary_
0
1import streamlit as st2import tensorflow as tf3import numpy as np4from PIL import Image5 6# Load the model7model = tf.keras.models.load_model("vgg19_binary_nonbinary.h5")8 9def preprocess_image(image):10 # Convert RGBA to RGB if the image has an alpha channel11 if image.mode == "RGBA":12 image = image.convert("RGB")13 # Resize and normalize the image14 image = image.resize((224, 224)) # Resize to match model input size15 image = np.array(image) / 255.0 # Normalize pixel values16 image = np.expand_dims(image, axis=0) # Add batch dimension17 return image18 19# Streamlit app20st.title("Binary vs Non-Binary Image Classification")21st.write("Upload an image to classify it as 'binary' or 'non-binary'.")22 23# File uploader24uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])25if uploaded_file is not None:26 # Display the uploaded image27 image = Image.open(uploaded_file)28 st.image(image, caption="Uploaded Image", use_column_width=True)29 st.write("Classifying...")30 31 # Preprocess and predict32 processed_image = preprocess_image(image)33 predictions = model.predict(processed_image)34 class_names = ["binary", "non-binary"]35 confidence = {class_names[i]: float(predictions[0][i]) for i in range(2)}36 37 # Display the prediction38 st.write("Prediction:")39 st.write(confidence)