diff --git a/glaucoma_app.py b/glaucoma_app.py index 540cd5d..b523b57 100644 --- a/glaucoma_app.py +++ b/glaucoma_app.py @@ -3,44 +3,50 @@ from PIL import Image, ImageOps import numpy as np -st.set_option('deprecation.showfileUploaderEncoding', False) +# Set Streamlit option to suppress deprecation warning +# st.set_option('deprecation.showfileUploaderEncoding', False) -# @st.cache(suppress_st_warning=True,allow_output_mutation=True) +# Function to preprocess image and make predictions def import_and_predict(image_data, model): - image = ImageOps.fit(image_data, (100,100),Image.ANTIALIAS) + # Resize image to the required input size of the model + image = ImageOps.fit(image_data, (100, 100), Image.Resampling.LANCZOS) image = image.convert('RGB') image = np.asarray(image) st.image(image, channels='RGB') - image = (image.astype(np.float32) / 255.0) - img_reshape = image[np.newaxis,...] + + # Normalize the image + image = image.astype(np.float32) / 255.0 + img_reshape = np.expand_dims(image, axis=0) + + # Prediction prediction = model.predict(img_reshape) return prediction +# Load the model (ensure 'my_model2.h5' is compatible with the current TensorFlow version) model = tf.keras.models.load_model('my_model2.h5') +# Streamlit interface st.write(""" - # ***Glaucoma detector*** - """ - ) + # ***Glaucoma Detector*** + This is a simple image classification web app to predict glaucoma through fundus image of the eye. + """) -st.write("This is a simple image classification web app to predict glaucoma through fundus image of eye") - -file = st.file_uploader("Please upload an image(jpg) file", type=["jpg"]) +file = st.file_uploader("Please upload an image (jpg) file", type=["jpg"]) +# Check if a file has been uploaded if file is None: - st.text("You haven't uploaded a jpg image file") + st.text("You haven't uploaded an image file.") else: + # Open image imageI = Image.open(file) + + # Make predictions prediction = import_and_predict(imageI, model) pred = prediction[0][0] - if(pred > 0.5): - st.write(""" - ## **Prediction:** You eye is Healthy. Great!! - """ - ) + + # Display results + if pred > 0.5: + st.write("## **Prediction:** Your eye appears healthy. Great!") st.balloons() else: - st.write(""" - ## **Prediction:** You are affected by Glaucoma. Please consult an ophthalmologist as soon as possible. - """ - ) + st.write("## **Prediction:** You may be affected by Glaucoma. Please consult an ophthalmologist.") diff --git a/requirements.txt b/requirements.txt index 33c0f99..b8ae026 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -tensorflow==2.3.0 +streamlit==0.81.1 +tensorflow==2.17.0 pillow==8.3.2 numpy==1.16.5 -streamlit==0.81.1