File size: 697 Bytes
bfb3c70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import tensorflow as tf
import gradio as gr
from preprocessing import preprocess_dicom

# Load model once
model = tf.keras.models.load_model("pneumonia_model_clean.keras")

def predict(file):
    img = preprocess_dicom(file.name)
    prob = float(model.predict(img)[0][0])

    if prob >= 0.5:
        return f"PNEUMONIA (confidence: {prob:.2f})"
    else:
        return f"NORMAL (confidence: {1 - prob:.2f})"

demo = gr.Interface(
    fn=predict,
    inputs=gr.File(label="Upload Chest X-ray (DICOM)"),
    outputs=gr.Textbox(label="Prediction"),
    title="Pneumonia Screening (DenseNet)",
    description="DICOM-based pneumonia screening model"
)

if __name__ == "__main__":
    demo.launch()