Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,13 +6,16 @@ from PIL import Image
|
|
| 6 |
# Load the model
|
| 7 |
model = tf.keras.models.load_model("vgg19_binary_nonbinary.h5")
|
| 8 |
|
| 9 |
-
# Define the preprocessing function
|
| 10 |
def preprocess_image(image):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
image = image.resize((224, 224)) # Resize to match model input size
|
| 12 |
image = np.array(image) / 255.0 # Normalize pixel values
|
| 13 |
image = np.expand_dims(image, axis=0) # Add batch dimension
|
| 14 |
return image
|
| 15 |
-
|
| 16 |
# Streamlit app
|
| 17 |
st.title("Binary vs Non-Binary Image Classification")
|
| 18 |
st.write("Upload an image to classify it as 'binary' or 'non-binary'.")
|
|
|
|
| 6 |
# Load the model
|
| 7 |
model = tf.keras.models.load_model("vgg19_binary_nonbinary.h5")
|
| 8 |
|
|
|
|
| 9 |
def preprocess_image(image):
|
| 10 |
+
# Convert RGBA to RGB if the image has an alpha channel
|
| 11 |
+
if image.mode == "RGBA":
|
| 12 |
+
image = image.convert("RGB")
|
| 13 |
+
# Resize and normalize the image
|
| 14 |
image = image.resize((224, 224)) # Resize to match model input size
|
| 15 |
image = np.array(image) / 255.0 # Normalize pixel values
|
| 16 |
image = np.expand_dims(image, axis=0) # Add batch dimension
|
| 17 |
return image
|
| 18 |
+
|
| 19 |
# Streamlit app
|
| 20 |
st.title("Binary vs Non-Binary Image Classification")
|
| 21 |
st.write("Upload an image to classify it as 'binary' or 'non-binary'.")
|