Zakia's picture
change app.py
9bfa451
raw
history blame
1.95 kB
# Bismillahir Rahmaanir Raheem
# Almadadh Ya Gause Radi Allahu Ta'alah Anh - Ameen
from fastai.vision.all import *
import gradio as gr
def is_pneumonia(x):
return (x.find('virus')!=-1 or x.find('bacteria')!=-1)
# load the trained fast ai model for predictions
learn = load_learner('model.pkl')
# define the function to call
categories = ('Pneumonia', 'Normal')
def predict(img):
pred, idx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
title = "Pediatric Pneumonia or Normal Chest X-Ray Predictor"
description = "A pediatric pneumonia or normal chest x-ray predictor model trained on the chest-xray-pneumonia dataset with fastai. The dataset is from: <a href='https://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='https://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: 81.25%"
article = "<p style='text-align: center'><span style='font-size: 15pt;'>Pediatric Pneumonia or Normal Chest X-Ray Predictor. Zakia Salod. 2022. </span></p>"
image = gr.inputs.Image(shape=(512, 512))
label = gr.outputs.Label()
examples = [
['person1_virus_6.jpeg'],
['NORMAL2-IM-0285-0001.jpeg'],
['person82_bacteria_404.jpeg'],
['NORMAL2-IM-0373-0001.jpeg'],
['person1618_virus_2805.jpeg'],
['NORMAL2-IM-0381-0001.jpeg'],
['person159_bacteria_747.jpeg'],
['NORMAL2-IM-0222-0001.jpeg'],
]
interpretation = 'default'
enable_queue = True
iface = gr.Interface(
fn=predict,
title=title,
description=description,
article=article,
inputs=image,
outputs=label,
theme="default",
examples=examples,
interpretation=interpretation,
enable_queue=enable_queue
)
iface.launch(inline=False)