File size: 1,297 Bytes
6a18290
 
 
 
 
eb522d1
6a18290
f612bb0
6a18290
 
 
ad25c15
6a18290
 
 
ad25c15
6a18290
eb522d1
8abc2d3
6a18290
ad25c15
6a18290
 
245e395
ad25c15
6a18290
 
bfd7638
6a18290
 
ad25c15
6a18290
 
 
 
ad25c15
 
6a18290
 
 
 
 
 
 
 
 
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
46
47
import streamlit as st
from PIL import Image
import tensorflow as tf
from tensorflow.keras.preprocessing.image import img_to_array
import numpy as np
import cv2

path_to_model = "nova.h5"

model = tf.keras.models.load_model(path_to_model)

#default height and width of the uploaded image
IMG_HEIGHT = 180
IMG_WIDTH = 180

# Preprocessing
def preprocess_image(image):
    img = cv2.resize(image, (IMG_HEIGHT, IMG_WIDTH))
    img_array = img_to_array(img)
    img_array = img_array / 255.0
    img_array = np.reshape(img_array, (1, IMG_HEIGHT, IMG_WIDTH, 3))
    return img_array



# Create the Streamlit app
def main():
    st.title("Nova'23 Classification model")    
    uploaded_image = st.file_uploader('Upload an image', type=['jpg', 'jpeg', 'png'])
    
    # Display the image
    if uploaded_image is not None:
        image = Image.open(uploaded_image)
        st.image(image, caption='Uploaded Image', use_column_width=True)
        
        input_image = preprocess_image(image) #preprocessing
        prediction = model.predict(input_image) #predicting
        
        # Display the prediction
        if prediction[0][0] > prediction[0][1]:
            st.write('Prediction: Normal')
        else:
            st.write('Prediction: Pneumonia')

if __name__ == '__main__':
    main()