mednow commited on
Commit
0db0111
·
verified ·
1 Parent(s): cff60ec

Upload 4 files

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. app.py +51 -0
  3. best_model_.keras +3 -0
  4. dockerfile +20 -0
  5. requirements.txt +9 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ best_model_.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from tensorflow.keras.preprocessing import image
4
+ import numpy as np
5
+
6
+ # Function to preprocess the image
7
+ def preprocess_image(img_path, img_height, img_width):
8
+ # Load the image in grayscale mode
9
+ img = image.load_img(img_path, target_size=(img_height, img_width), color_mode='grayscale')
10
+ # Convert the image to a numpy array
11
+ img_array = image.img_to_array(img)
12
+ # Expand dimensions to match the model's input shape
13
+ img_array = np.expand_dims(img_array, axis=0)
14
+ # Normalize the image
15
+ img_array = img_array / 255.0
16
+ return img_array
17
+
18
+ # Load the best model
19
+ @st.cache_resource
20
+ def load_model():
21
+ return tf.keras.models.load_model('best_model_.keras')
22
+
23
+ model = load_model()
24
+
25
+ # Streamlit UI
26
+ st.title("X-ray Image Classification")
27
+ st.write("Upload an X-ray image to classify it as Normal or Pneumonia.")
28
+
29
+ # File uploader for image
30
+ uploaded_file = st.file_uploader("Choose an X-ray image...", type="jpeg")
31
+
32
+ if uploaded_file is not None:
33
+ # Save the uploaded file to a temporary location
34
+ with open("temp.jpeg", "wb") as f:
35
+ f.write(uploaded_file.getbuffer())
36
+
37
+ # Preprocess the image
38
+ img_height, img_width = 224, 224 # Use the same dimensions as used during training
39
+ preprocessed_img = preprocess_image("temp.jpeg", img_height, img_width)
40
+
41
+ # Display the uploaded image
42
+ st.image(uploaded_file, caption="Uploaded X-ray Image", use_column_width=True)
43
+
44
+ # Make predictions
45
+ prediction = model.predict(preprocessed_img)
46
+
47
+ # Output the prediction
48
+ if prediction[0] > 0.5:
49
+ st.write("Prediction: Pneumonia")
50
+ else:
51
+ st.write("Prediction: Normal")
best_model_.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:86a7ca2de31117d4cfb752441c31ea3a85f04049562281c01f8010af6e0df1c9
3
+ size 1148000380
dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Python runtime as a parent image
2
+ FROM python:3.9-slim
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Copy the requirements file into the container
8
+ COPY requirements.txt ./
9
+
10
+ # Install any necessary dependencies
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # Copy the rest of the application code into the container
14
+ COPY . .
15
+
16
+ # Expose the port the app runs on
17
+ EXPOSE 8501
18
+
19
+ # Command to run the Streamlit app
20
+ CMD ["streamlit", "run", "app.py"]
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ tensorflow
2
+ opencv-python
3
+ matplotlib
4
+ streamlit
5
+ numpy
6
+ scipy
7
+ scikit-learn
8
+ keras_tuner
9
+ scikeras