Spaces:
Configuration error
Configuration error
File size: 1,745 Bytes
0d34430 |
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import gradio as gr
import numpy as np
from PIL import Image
from tensorflow.keras.models import load_model
from huggingface_hub import hf_hub_download
# Download the model from Hugging Face Hub
model_path = hf_hub_download(repo_id="TaliZG03/kidney_normal_CT_classifier_model", filename="model.keras")
# Load the model
model = load_model(model_path)
# Preprocess function
def preprocess(image):
image = image.resize((300, 300)).convert("RGB")
image = np.array(image) / 255.0
return np.expand_dims(image, axis=0)
# Prediction function with flagging
def predict(image):
input_array = preprocess(image)
prediction = model.predict(input_array)[0][0]
label = "NORMAL" if prediction >= 0.5 else "ABNORMAL"
confidence = prediction if label == "NORMAL" else 1 - prediction
if label == "NORMAL" and confidence >= 0.7:
explanation = " The kidney CT scan appears normal with high confidence."
attention_flag = ""
elif label == "NORMAL":
explanation = " The scan appears normal, but the model's confidence is low. Consider radiologist review."
attention_flag = " FLAGGED FOR RADIOLOGIST REVIEW"
else:
explanation = " The kidney CT scan shows signs of abnormality. Immediate radiologist attention is recommended."
attention_flag = " FLAGGED FOR RADIOLOGIST REVIEW"
return f""" Prediction: {label}
Confidence: {confidence:.2%}
{explanation}
{attention_flag}"""
# Gradio Interface
demo = gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"),
outputs="text",
title="Kidney CT Classifier",
description="Upload a kidney CT image. The model will predict if it's NORMAL or ABNORMAL. Flagged results go to radiologist review."
)
demo.launch() |