Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,19 +6,21 @@ from PIL import Image
|
|
| 6 |
# Load the model
|
| 7 |
model = tf.keras.models.load_model("vgg19_binary_nonbinary.h5")
|
| 8 |
|
| 9 |
-
#
|
| 10 |
def preprocess_image(image):
|
| 11 |
-
image = image.resize((224, 224))
|
| 12 |
-
image = np.array(image) / 255.0
|
| 13 |
-
image = np.expand_dims(image, axis=0)
|
| 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'.")
|
| 19 |
|
|
|
|
| 20 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 21 |
if uploaded_file is not None:
|
|
|
|
| 22 |
image = Image.open(uploaded_file)
|
| 23 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 24 |
st.write("Classifying...")
|
|
@@ -29,5 +31,6 @@ if uploaded_file is not None:
|
|
| 29 |
class_names = ["binary", "non-binary"]
|
| 30 |
confidence = {class_names[i]: float(predictions[0][i]) for i in range(2)}
|
| 31 |
|
|
|
|
| 32 |
st.write("Prediction:")
|
| 33 |
st.write(confidence)
|
|
|
|
| 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'.")
|
| 19 |
|
| 20 |
+
# File uploader
|
| 21 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 22 |
if uploaded_file is not None:
|
| 23 |
+
# Display the uploaded image
|
| 24 |
image = Image.open(uploaded_file)
|
| 25 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 26 |
st.write("Classifying...")
|
|
|
|
| 31 |
class_names = ["binary", "non-binary"]
|
| 32 |
confidence = {class_names[i]: float(predictions[0][i]) for i in range(2)}
|
| 33 |
|
| 34 |
+
# Display the prediction
|
| 35 |
st.write("Prediction:")
|
| 36 |
st.write(confidence)
|