Update app.py
Browse files
app.py
CHANGED
|
@@ -3,11 +3,18 @@ import numpy as np
|
|
| 3 |
import cv2
|
| 4 |
import tensorflow as tf
|
| 5 |
from PIL import Image
|
| 6 |
-
from sklearn.preprocessing import LabelEncoder
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Function to load and preprocess the uploaded image
|
| 9 |
def load_and_preprocess_image(uploaded_file):
|
| 10 |
-
# Convert uploaded file to a format suitable for OpenCV
|
| 11 |
img = Image.open(uploaded_file)
|
| 12 |
img = img.convert("RGB") # Convert to RGB if it's in another format
|
| 13 |
img = np.array(img) # Convert to NumPy array
|
|
@@ -26,9 +33,6 @@ def predict_image(img):
|
|
| 26 |
def get_class_label(predicted_class_index):
|
| 27 |
return label_encoder.inverse_transform([predicted_class_index])[0] # Get class label
|
| 28 |
|
| 29 |
-
# Load your pre-trained model (Make sure this matches the version used during training)
|
| 30 |
-
model = tf.keras.models.load_model('dementia_cnn_model.h5')
|
| 31 |
-
|
| 32 |
# Streamlit App UI
|
| 33 |
st.title("Dementia Detection using CNN")
|
| 34 |
st.write("Upload a brain scan (JPG format), and the model will predict its class.")
|
|
@@ -38,7 +42,7 @@ uploaded_file = st.file_uploader("Choose a JPG image...", type="jpg")
|
|
| 38 |
|
| 39 |
if uploaded_file is not None:
|
| 40 |
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 41 |
-
st.write("
|
| 42 |
|
| 43 |
# Load and preprocess the image
|
| 44 |
processed_image = load_and_preprocess_image(uploaded_file)
|
|
|
|
| 3 |
import cv2
|
| 4 |
import tensorflow as tf
|
| 5 |
from PIL import Image
|
| 6 |
+
from sklearn.preprocessing import LabelEncoder
|
| 7 |
+
|
| 8 |
+
# Load your pre-trained model (Make sure this matches the version used during training)
|
| 9 |
+
model = tf.keras.models.load_model('dementia_cnn_model.h5')
|
| 10 |
+
|
| 11 |
+
# Example class labels (update this list with your actual class labels)
|
| 12 |
+
class_labels = ['Non Demented', 'Very mild Dementia', 'Mild Dementia', 'Moderate Dementia']
|
| 13 |
+
label_encoder = LabelEncoder()
|
| 14 |
+
label_encoder.fit(class_labels) # Fit the label encoder with your class labels
|
| 15 |
|
| 16 |
# Function to load and preprocess the uploaded image
|
| 17 |
def load_and_preprocess_image(uploaded_file):
|
|
|
|
| 18 |
img = Image.open(uploaded_file)
|
| 19 |
img = img.convert("RGB") # Convert to RGB if it's in another format
|
| 20 |
img = np.array(img) # Convert to NumPy array
|
|
|
|
| 33 |
def get_class_label(predicted_class_index):
|
| 34 |
return label_encoder.inverse_transform([predicted_class_index])[0] # Get class label
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
# Streamlit App UI
|
| 37 |
st.title("Dementia Detection using CNN")
|
| 38 |
st.write("Upload a brain scan (JPG format), and the model will predict its class.")
|
|
|
|
| 42 |
|
| 43 |
if uploaded_file is not None:
|
| 44 |
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 45 |
+
st.write("Classifying...")
|
| 46 |
|
| 47 |
# Load and preprocess the image
|
| 48 |
processed_image = load_and_preprocess_image(uploaded_file)
|