Spaces:
Build error
Build error
Upload 2 files
Browse files- app.py +55 -0
- my_pneumonia_detection_model.h5 +3 -0
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
from tensorflow.keras.preprocessing import image as keras_image
|
4 |
+
import numpy as np
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
# Load the pre-trained model
|
8 |
+
model = load_model('CNN_model.h5')
|
9 |
+
img_width, img_height = 256, 256
|
10 |
+
|
11 |
+
# from tensorflow.keras.preprocessing import image as keras_image
|
12 |
+
|
13 |
+
def preprocess_image(image):
|
14 |
+
# Convert image to RGB if it has fewer than 3 channels
|
15 |
+
if image.mode != 'RGB':
|
16 |
+
image = image.convert('RGB')
|
17 |
+
# Resize image to match model input shape
|
18 |
+
image = image.resize((img_width, img_height))
|
19 |
+
# Convert image to numpy array
|
20 |
+
image = keras_image.img_to_array(image)
|
21 |
+
# Ensure the image has 3 color channels (RGB)
|
22 |
+
if image.shape[-1] != 3:
|
23 |
+
raise ValueError("Image does not have 3 color channels (RGB)")
|
24 |
+
# Reshape image to add batch dimension
|
25 |
+
image = np.expand_dims(image, axis=0)
|
26 |
+
# Normalize pixel values
|
27 |
+
image = image / 255.0
|
28 |
+
return image
|
29 |
+
|
30 |
+
|
31 |
+
# Streamlit app
|
32 |
+
st.title('🌡️🦠Pneumonia Detection Model')
|
33 |
+
|
34 |
+
uploaded_file = st.file_uploader("Choose chest X-ray image...", type=["jpg", "jpeg", "png"])
|
35 |
+
|
36 |
+
if uploaded_file is not None:
|
37 |
+
# Display uploaded image
|
38 |
+
image = Image.open(uploaded_file)
|
39 |
+
st.image(image,width=400)
|
40 |
+
|
41 |
+
# Preprocess the image
|
42 |
+
processed_image = preprocess_image(image)
|
43 |
+
|
44 |
+
# Make prediction
|
45 |
+
prediction = model.predict(processed_image)
|
46 |
+
|
47 |
+
# Get class label
|
48 |
+
class_label = np.argmax(prediction)
|
49 |
+
|
50 |
+
# Display prediction
|
51 |
+
if class_label==1:
|
52 |
+
st.error('Affected by Pneumonia', icon="🚨")
|
53 |
+
else:
|
54 |
+
st.success('Result is NORMAL !!', icon="😊")
|
55 |
+
|
my_pneumonia_detection_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5d9d85f19d75ee0e133367cb82a065462909f271ec0726c727038add1321cb9a
|
3 |
+
size 97909472
|