Update app.py
Browse files
app.py
CHANGED
@@ -1,119 +1,3 @@
|
|
1 |
-
# import streamlit as st
|
2 |
-
# import tensorflow as tf
|
3 |
-
# from tensorflow.keras.preprocessing import image
|
4 |
-
# import numpy as np
|
5 |
-
# from PIL import Image
|
6 |
-
# import base64
|
7 |
-
|
8 |
-
# hide_streamlit_style = """
|
9 |
-
# <style>
|
10 |
-
# div[data-testid="stToolbar"] {
|
11 |
-
# visibility: hidden;
|
12 |
-
# height: 0%;
|
13 |
-
# position: fixed;
|
14 |
-
# }
|
15 |
-
# div[data-testid="stDecoration"] {
|
16 |
-
# visibility: hidden;
|
17 |
-
# height: 0%;
|
18 |
-
# position: fixed;
|
19 |
-
# }
|
20 |
-
# div[data-testid="stStatusWidget"] {
|
21 |
-
# visibility: hidden;
|
22 |
-
# height: 0%;
|
23 |
-
# position: fixed;
|
24 |
-
# }
|
25 |
-
# #MainMenu {
|
26 |
-
# visibility: hidden;
|
27 |
-
# height: 0%;
|
28 |
-
# }
|
29 |
-
# header {
|
30 |
-
# visibility: hidden;
|
31 |
-
# height: 0%;
|
32 |
-
# }
|
33 |
-
# footer {
|
34 |
-
# visibility: hidden;
|
35 |
-
# height: 0%;
|
36 |
-
# }
|
37 |
-
# </style>
|
38 |
-
# """
|
39 |
-
# st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
40 |
-
|
41 |
-
|
42 |
-
# # Load the pre-trained model
|
43 |
-
# model = tf.keras.models.load_model('model.h5')
|
44 |
-
# # Define the target size for the model
|
45 |
-
# img_size = (224, 224)
|
46 |
-
|
47 |
-
# # Function to preprocess the image
|
48 |
-
# def preprocess_image(img):
|
49 |
-
# img = image.load_img(img, target_size=img_size)
|
50 |
-
# img_array = image.img_to_array(img)
|
51 |
-
# img_array = img_array / 255.0 # Normalize pixel values to between 0 and 1
|
52 |
-
# img_array = np.expand_dims(img_array, axis=0)
|
53 |
-
# return img_array
|
54 |
-
|
55 |
-
# # Function to make predictions
|
56 |
-
# def predict_image(img):
|
57 |
-
# img_array = preprocess_image(img)
|
58 |
-
# prediction = model.predict(img_array)
|
59 |
-
# prediction = np.squeeze(prediction, axis=0)
|
60 |
-
# return prediction
|
61 |
-
|
62 |
-
# # Function to display and provide a download link for an image
|
63 |
-
# def display_image_with_download(image_path, caption, download_text):
|
64 |
-
# image = Image.open(image_path)
|
65 |
-
# st.image(image, caption=caption, use_column_width=True)
|
66 |
-
|
67 |
-
# # Generate a download link
|
68 |
-
# with open(image_path, 'rb') as f:
|
69 |
-
# data = f.read()
|
70 |
-
# base64_data = base64.b64encode(data).decode('utf-8')
|
71 |
-
# href = f'<a href="data:application/octet-stream;base64,{base64_data}" download="{download_text}.jpg">Download {download_text}</a>'
|
72 |
-
# st.markdown(href, unsafe_allow_html=True)
|
73 |
-
|
74 |
-
# # Streamlit app
|
75 |
-
# def main():
|
76 |
-
|
77 |
-
# st.title("Pneumonia Detection")
|
78 |
-
|
79 |
-
# # Allow user to upload an image
|
80 |
-
# uploaded_file = st.file_uploader("Upload a chest X-ray image in JPG format...", type="jpg")
|
81 |
-
|
82 |
-
# # Example instructions
|
83 |
-
# st.markdown("""
|
84 |
-
# Example Instructions:
|
85 |
-
# - Upload a chest X-ray image in JPG format.
|
86 |
-
# - Or, download sample images below and check the predictions.
|
87 |
-
# """)
|
88 |
-
|
89 |
-
# # Provide links to download sample images
|
90 |
-
# st.write("**Download Sample Images:**")
|
91 |
-
|
92 |
-
# pneumonic_download = st.button("Download Pneumonic Image")
|
93 |
-
# normal_download = st.button("Download Normal Image")
|
94 |
-
|
95 |
-
# if pneumonic_download:
|
96 |
-
# pneumonic_image_path = "test-pneumonia_028.jpg" # Replace with actual path
|
97 |
-
# display_image_with_download(pneumonic_image_path, "Pneumonic Image", "Pneumonic Image")
|
98 |
-
|
99 |
-
# if normal_download:
|
100 |
-
# normal_image_path = "test-normal_001.jpg" # Replace with actual path
|
101 |
-
# display_image_with_download(normal_image_path, "Normal Image", "Normal Image")
|
102 |
-
|
103 |
-
# if uploaded_file is not None:
|
104 |
-
# st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
105 |
-
|
106 |
-
# # Make predictions
|
107 |
-
# prediction = predict_image(uploaded_file)
|
108 |
-
|
109 |
-
# # Display the results
|
110 |
-
# st.write("**Prediction:**")
|
111 |
-
# class_label = "Pneumonia" if prediction > 0.5 else "Normal"
|
112 |
-
# st.write(f"The image is classified as **{class_label}**.")
|
113 |
-
|
114 |
-
# if __name__ == "__main__":
|
115 |
-
# main()
|
116 |
-
|
117 |
import streamlit as st
|
118 |
import tensorflow as tf
|
119 |
from tensorflow.keras.preprocessing import image
|
@@ -121,15 +5,40 @@ import numpy as np
|
|
121 |
from PIL import Image
|
122 |
import base64
|
123 |
|
124 |
-
# Hide Streamlit menu and footer
|
125 |
hide_streamlit_style = """
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
132 |
|
|
|
133 |
# Load the pre-trained model
|
134 |
model = tf.keras.models.load_model('model.h5')
|
135 |
# Define the target size for the model
|
@@ -164,62 +73,26 @@ def display_image_with_download(image_path, caption, download_text):
|
|
164 |
|
165 |
# Streamlit app
|
166 |
def main():
|
167 |
-
|
168 |
-
|
169 |
page_title="Pneumonia Detection App",
|
170 |
page_icon=":microscope:",
|
171 |
layout="wide"
|
172 |
)
|
173 |
-
|
174 |
-
|
175 |
-
st.markdown("""
|
176 |
-
<style>
|
177 |
-
body {
|
178 |
-
background-color: #f5f5f5;
|
179 |
-
}
|
180 |
-
.st-bw {
|
181 |
-
background-color: #ffffff;
|
182 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
183 |
-
border-radius: 10px;
|
184 |
-
padding: 20px;
|
185 |
-
margin-bottom: 20px;
|
186 |
-
}
|
187 |
-
.st-bw img {
|
188 |
-
max-width: 100%;
|
189 |
-
border-radius: 10px;
|
190 |
-
}
|
191 |
-
.st-bw a {
|
192 |
-
color: #007bff;
|
193 |
-
}
|
194 |
-
.st-bw button {
|
195 |
-
background-color: #007bff;
|
196 |
-
color: #ffffff;
|
197 |
-
border: none;
|
198 |
-
padding: 10px 20px;
|
199 |
-
font-size: 16px;
|
200 |
-
border-radius: 5px;
|
201 |
-
cursor: pointer;
|
202 |
-
}
|
203 |
-
.st-bw button:hover {
|
204 |
-
background-color: #0056b3;
|
205 |
-
}
|
206 |
-
</style>
|
207 |
-
""", unsafe_allow_html=True)
|
208 |
-
|
209 |
-
# Display app title
|
210 |
-
st.title("Pneumonia Detection App")
|
211 |
|
212 |
# Allow user to upload an image
|
213 |
-
uploaded_file = st.file_uploader("Upload a chest X-ray image in JPG format...", type="jpg"
|
214 |
|
215 |
# Example instructions
|
216 |
st.markdown("""
|
217 |
-
|
218 |
- Upload a chest X-ray image in JPG format.
|
219 |
- Or, download sample images below and check the predictions.
|
220 |
""")
|
221 |
|
222 |
-
|
223 |
st.write("**Download Sample Images:**")
|
224 |
|
225 |
pneumonic_download = st.button("Download Pneumonic Image")
|
@@ -234,10 +107,7 @@ def main():
|
|
234 |
display_image_with_download(normal_image_path, "Normal Image", "Normal Image")
|
235 |
|
236 |
if uploaded_file is not None:
|
237 |
-
# Display the uploaded image in a styled container
|
238 |
-
st.markdown('<div class="st-bw">', unsafe_allow_html=True)
|
239 |
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
240 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
241 |
|
242 |
# Make predictions
|
243 |
prediction = predict_image(uploaded_file)
|
@@ -246,6 +116,7 @@ def main():
|
|
246 |
st.write("**Prediction:**")
|
247 |
class_label = "Pneumonia" if prediction > 0.5 else "Normal"
|
248 |
st.write(f"The image is classified as **{class_label}**.")
|
249 |
-
|
250 |
if __name__ == "__main__":
|
251 |
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import tensorflow as tf
|
3 |
from tensorflow.keras.preprocessing import image
|
|
|
5 |
from PIL import Image
|
6 |
import base64
|
7 |
|
|
|
8 |
hide_streamlit_style = """
|
9 |
+
<style>
|
10 |
+
div[data-testid="stToolbar"] {
|
11 |
+
visibility: hidden;
|
12 |
+
height: 0%;
|
13 |
+
position: fixed;
|
14 |
+
}
|
15 |
+
div[data-testid="stDecoration"] {
|
16 |
+
visibility: hidden;
|
17 |
+
height: 0%;
|
18 |
+
position: fixed;
|
19 |
+
}
|
20 |
+
div[data-testid="stStatusWidget"] {
|
21 |
+
visibility: hidden;
|
22 |
+
height: 0%;
|
23 |
+
position: fixed;
|
24 |
+
}
|
25 |
+
#MainMenu {
|
26 |
+
visibility: hidden;
|
27 |
+
height: 0%;
|
28 |
+
}
|
29 |
+
header {
|
30 |
+
visibility: hidden;
|
31 |
+
height: 0%;
|
32 |
+
}
|
33 |
+
footer {
|
34 |
+
visibility: hidden;
|
35 |
+
height: 0%;
|
36 |
+
}
|
37 |
+
</style>
|
38 |
+
"""
|
39 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
40 |
|
41 |
+
|
42 |
# Load the pre-trained model
|
43 |
model = tf.keras.models.load_model('model.h5')
|
44 |
# Define the target size for the model
|
|
|
73 |
|
74 |
# Streamlit app
|
75 |
def main():
|
76 |
+
|
77 |
+
st.set_page_config(
|
78 |
page_title="Pneumonia Detection App",
|
79 |
page_icon=":microscope:",
|
80 |
layout="wide"
|
81 |
)
|
82 |
+
|
83 |
+
st.title("Pneumonia Detection")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
# Allow user to upload an image
|
86 |
+
uploaded_file = st.file_uploader("Upload a chest X-ray image in JPG format...", type="jpg")
|
87 |
|
88 |
# Example instructions
|
89 |
st.markdown("""
|
90 |
+
Example Instructions:
|
91 |
- Upload a chest X-ray image in JPG format.
|
92 |
- Or, download sample images below and check the predictions.
|
93 |
""")
|
94 |
|
95 |
+
# Provide links to download sample images
|
96 |
st.write("**Download Sample Images:**")
|
97 |
|
98 |
pneumonic_download = st.button("Download Pneumonic Image")
|
|
|
107 |
display_image_with_download(normal_image_path, "Normal Image", "Normal Image")
|
108 |
|
109 |
if uploaded_file is not None:
|
|
|
|
|
110 |
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
|
|
111 |
|
112 |
# Make predictions
|
113 |
prediction = predict_image(uploaded_file)
|
|
|
116 |
st.write("**Prediction:**")
|
117 |
class_label = "Pneumonia" if prediction > 0.5 else "Normal"
|
118 |
st.write(f"The image is classified as **{class_label}**.")
|
119 |
+
|
120 |
if __name__ == "__main__":
|
121 |
main()
|
122 |
+
|