File size: 1,769 Bytes
2a9d41f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e090bf
2a9d41f
 
 
 
 
45b79a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import streamlit as st
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
import numpy as np

# Load the model and weights
model_path = "Pneumonia_detection_using_CNN.h5"
weights_path = "Pneumonia_detection_using_CNN.weights.h5"

model = load_model(model_path)
model.load_weights(weights_path)

# Streamlit app
st.title('Pneumonia Detection App')

# File uploader for image input
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "webp"])

if uploaded_file is not None:
    # Display the uploaded image
    st.image(uploaded_file, caption='Uploaded Image', use_column_width=True)
    
    if st.button('Predict', key='predict_button'):
        # Load and preprocess the image
        img = image.load_img(uploaded_file, target_size=(224, 224))
        img_array = image.img_to_array(img)
        img_array = np.expand_dims(img_array, axis=0)

        # Make a prediction
        prediction = model.predict(img_array)

        # Display the prediction with confidence level in large highlighted text
        class_names = ['Normal', 'Pneumonia']
        predicted_class = class_names[np.argmax(prediction)]
        confidence_level = np.max(prediction) * 100  # Convert probability to percentage

        # Set text color based on prediction
        if predicted_class == 'Normal':
            text_color = 'green'
        else:
            text_color = 'red'

        # Display prediction and confidence level in large highlighted text
        st.markdown(f'<p style="font-size:32px; color:{text_color};">Prediction: {predicted_class}</p>', unsafe_allow_html=True)
        st.markdown(f'<p style="font-size:32px; color:{text_color};">Confidence: {confidence_level:.2f}%</p>', unsafe_allow_html=True)