|
|
|
|
|
|
|
|
|
from fastai.vision.all import *
|
|
import gradio as gr
|
|
|
|
|
|
|
|
|
|
def is_pneumonia(x):
|
|
return (x.find('virus')!=-1 or x.find('bacteria')!=-1)
|
|
|
|
|
|
|
|
learn = load_learner('pneumonia_model.pkl')
|
|
|
|
|
|
|
|
categories = ('Pneumonia', 'Normal')
|
|
|
|
|
|
|
|
def predict(img):
|
|
pred, idx, probs = learn.predict(img)
|
|
return dict(zip(categories, map(float, probs)))
|
|
|
|
|
|
|
|
title = "Pediatric Pneumonia Chest X-Ray Predictor"
|
|
|
|
|
|
|
|
description = """
|
|
A pediatric pneumonia chest x-ray predictor model trained on the chest-xray-pneumonia dataset using ResNet34 via
|
|
<a href='http://www.fast.ai/' target='_blank'>fast.ai</a>. The dataset is from:
|
|
<a href='http://www.kaggle.com/datasets/paultimothymooney/chest-xray-pneumonia' target='_blank'>Chest X-Ray Images (Pneumonia)</a>
|
|
and the associated scientific journal paper is
|
|
<a href='http://www.cell.com/cell/fulltext/S0092-8674(18)30154-5' target='_blank'>Identifying Medical Diagnoses and Treatable
|
|
Diseases by Image-Based Deep Learning</a>. The accuracy of the model is: 87.50%
|
|
"""
|
|
|
|
|
|
|
|
article = """
|
|
<p style='text-align: center'><span style='font-size: 15pt;'>Pediatric Pneumonia Chest X-Ray Predictor. Dr Zakia Salod. 2024. </span></p>
|
|
"""
|
|
|
|
|
|
|
|
image = gr.Image(height=512, width=512)
|
|
|
|
|
|
label = gr.Label()
|
|
|
|
|
|
|
|
examples = [
|
|
['NORMAL2-IM-0222-0001.jpeg'],
|
|
['person159_bacteria_747.jpeg'],
|
|
['person1618_virus_2805.jpeg'],
|
|
]
|
|
|
|
|
|
|
|
iface = gr.Interface(
|
|
fn=predict,
|
|
title=title,
|
|
description=description,
|
|
article=article,
|
|
inputs=image,
|
|
outputs=label,
|
|
theme="default",
|
|
examples=examples
|
|
)
|
|
|
|
|
|
|
|
iface.launch(inline=False)
|
|
|