Spaces:
Sleeping
Sleeping
##importing the libraries | |
import numpy as np | |
import pandas as pd | |
from PIL import Image | |
import tensorflow as tf | |
import os | |
from tensorflow.keras.models import load_model | |
import gradio as gr | |
# Load your trained model | |
model = load_model('tb_pretrained.h5') | |
### Preprocess the new image | |
def predict_image(test_image): | |
# img = cv2.imread(test_image) | |
img = np.array(test_image) | |
image_1 = tf.image.resize(img, (256,256)) | |
image_processed = np.expand_dims(image_1/256, 0) | |
##prediction | |
yhat = model.predict(image_processed) | |
## setting a threshold | |
if yhat[0][1] > 0.70: | |
return (f'There is {round((yhat[0][1])*100,2)}% chance of the image being normal') | |
elif yhat[0][0] > 0.9: | |
return (f'There is {round((yhat[0][0])*100,2)}% chance of an abnormality either than TB being present') | |
else: | |
return (f'There is a chance of TB being present') | |
platform = gr.Interface( fn = predict_image, | |
title ="TB CADx", | |
inputs = "image", | |
outputs = "label", | |
description="""This is a computer aided detection tool that helps | |
clinicians quickly classify chest X-ray images into either normal, | |
unhealthy but no TB or High chance of TB""", | |
article = """This tool is for research and by all means not meant to replace | |
the WHO recommended guidelines on diagnosing TB""" ) | |
platform.launch(inline=True, share=True) |