Spaces:
Sleeping
Sleeping
import streamlit as st | |
from PIL import Image | |
import numpy as np | |
import tensorflow as tf | |
from tensorflow import keras | |
# Load the saved model | |
loaded_model = keras.models.load_model('tuned_model_classic.h5') | |
# Define the class labels (you can customize these according to your problem) | |
class_labels = ['Stroke', 'Non-Stroke'] | |
# Streamlit App | |
st.title('Stroke Classifier') | |
st.write('This an app developed with collaboration of a doctor and CS student for the purpose of addressing stroke people faster in Bangladesh using AI, I used a classic CNN Architect') | |
st.write('Upload an image to classify') | |
uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) | |
if uploaded_image is not None: | |
# Read the image and preprocess it | |
image = Image.open(uploaded_image) | |
image = image.convert('RGB') | |
image = image.resize((150, 150)) # Resize to match the model's input shape | |
image = np.array(image) # Convert PIL image to numpy array | |
image = image / 255.0 # Normalize pixel values (similar to how you did in the model training) | |
# Make prediction using the loaded model | |
prediction = loaded_model.predict(np.expand_dims(image, axis=0))[0] | |
predicted_class_index = np.argmax(prediction) | |
predicted_class = class_labels[predicted_class_index] | |
confidence = prediction[predicted_class_index] | |
# Display the uploaded image and the prediction | |
st.image(image, caption=f'Uploaded Image', use_column_width=True) | |
# Check if the predicted class is "Non-Stroke" and the confidence is high (you can adjust the threshold) | |
if predicted_class == 'Non-Stroke' and confidence > 0.8: | |
st.write(f'Predicted Class: Uncertain (Possibly both Stroke and Non-Stroke) (Confidence: {confidence:.2f})') | |
else: | |
st.write(f'Predicted Class: {predicted_class} (Confidence: {confidence:.2f})') |