Senasu commited on
Commit
1f62bfc
·
verified ·
1 Parent(s): 83f1c2f

Upload main files

Browse files
Files changed (3) hide show
  1. app.py +63 -0
  2. cnn_model.h5 +3 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from tensorflow.keras.models import load_model
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Load the model
7
+ model = load_model('cnn_model.h5')
8
+
9
+ # Function to process the uploaded image
10
+ def process_image(img):
11
+ img = img.convert("RGB") # Convert to RGB
12
+ img = img.resize((64, 64)) # Resize to match model input
13
+ img = np.array(img) / 255.0 # Normalize pixel values
14
+ img = np.expand_dims(img, axis=0) # Expand dimensions for batch processing
15
+ return img
16
+
17
+ # Streamlit App
18
+ st.set_page_config(page_title="Pneumonia Detector", page_icon="🩺", layout="centered")
19
+
20
+ # Apply custom styling
21
+ st.markdown(
22
+ """
23
+ <style>
24
+ .main {background-color: #e3f2fd;} /* Light blue background */
25
+ h1 {color: #008080; text-align: center;} /* Teal color title */
26
+ .stButton button {background-color: #008080; color: white; font-size: 18px;} /* Stylish button */
27
+ .result-box {padding: 10px; border-radius: 10px; font-size: 20px; text-align: center; font-weight: bold;}
28
+ </style>
29
+ """,
30
+ unsafe_allow_html=True,
31
+ )
32
+
33
+ # Title
34
+ st.title("🩺 Pneumonia Detection System")
35
+ st.write("Upload a chest X-ray image to check if it indicates Pneumonia or is Normal.")
36
+
37
+ # File uploader
38
+ file = st.file_uploader("📷 Upload an Image", type=["jpg", "jpeg", "png"])
39
+
40
+ if file is not None:
41
+ # Display uploaded image
42
+ img = Image.open(file)
43
+ st.image(img, caption="Uploaded Image", use_column_width=True)
44
+
45
+ # Predict button
46
+ if st.button("🔍 Predict"):
47
+ with st.spinner("Analyzing... ⏳"):
48
+ image = process_image(img)
49
+ predictions = model.predict(image)
50
+ predicted_class = np.argmax(predictions)
51
+
52
+ # Class names
53
+ class_names = ["NORMAL", "PNEUMONIA"]
54
+ result_text = class_names[predicted_class]
55
+
56
+ # Dynamic coloring for results
57
+ color = "green" if predicted_class == 0 else "red"
58
+
59
+ # Display result
60
+ st.markdown(
61
+ f'<div class="result-box" style="background-color: {color}; color: white;">{result_text}</div>',
62
+ unsafe_allow_html=True,
63
+ )
cnn_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:29d5f4037741df724d8ff85cf8d1d4781f3042dc6b1a26b6f861359002ad060d
3
+ size 134058032
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ tensorflow
3
+ pillow