affanthinks commited on
Commit
bfb3c70
·
verified ·
1 Parent(s): 7c6a242

Upload 4 files

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. app.py +26 -0
  3. pneumonia_model_clean.keras +3 -0
  4. preprocessing.py +17 -0
  5. requirements.txt +7 -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
+ pneumonia_model_clean.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import gradio as gr
3
+ from preprocessing import preprocess_dicom
4
+
5
+ # Load model once
6
+ model = tf.keras.models.load_model("pneumonia_model_clean.keras")
7
+
8
+ def predict(file):
9
+ img = preprocess_dicom(file.name)
10
+ prob = float(model.predict(img)[0][0])
11
+
12
+ if prob >= 0.5:
13
+ return f"PNEUMONIA (confidence: {prob:.2f})"
14
+ else:
15
+ return f"NORMAL (confidence: {1 - prob:.2f})"
16
+
17
+ demo = gr.Interface(
18
+ fn=predict,
19
+ inputs=gr.File(label="Upload Chest X-ray (DICOM)"),
20
+ outputs=gr.Textbox(label="Prediction"),
21
+ title="Pneumonia Screening (DenseNet)",
22
+ description="DICOM-based pneumonia screening model"
23
+ )
24
+
25
+ if __name__ == "__main__":
26
+ demo.launch()
pneumonia_model_clean.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6135dbfa67bf67e9b7ef53d1c3d5db05bc3f701495a7659b65ddfc490cbcbd60
3
+ size 30710690
preprocessing.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pydicom
3
+ import cv2
4
+
5
+ def load_dicom_image(path):
6
+ ds = pydicom.dcmread(path)
7
+ img = ds.pixel_array.astype(np.float32)
8
+ return img
9
+
10
+ def resize_image(img, target_size=(224, 224)):
11
+ return cv2.resize(img, target_size, interpolation=cv2.INTER_LINEAR)
12
+
13
+ def normalize_image(img):
14
+ return img / 255.0
15
+
16
+ def to_3channel(img):
17
+ return np.stack([img, img, img], axis=-1)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ tensorflow>=2.16
2
+ keras>=3.0
3
+ gradio
4
+ numpy
5
+ pydicom
6
+ opencv-python-headless
7
+