Spaces:
Configuration error
Configuration error
Delete app.py
Browse files
app.py
DELETED
@@ -1,47 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
from PIL import Image
|
4 |
-
from tensorflow.keras.models import load_model
|
5 |
-
from huggingface_hub import hf_hub_download
|
6 |
-
|
7 |
-
model_path = hf_hub_download(repo_id="TaliZG03/kidney_normal_CT_classifier_model", filename="model.keras")
|
8 |
-
model = load_model(model_path)
|
9 |
-
|
10 |
-
def preprocess(image):
|
11 |
-
image = image.resize((300, 300)).convert("RGB")
|
12 |
-
image = np.array(image) / 255.0
|
13 |
-
return np.expand_dims(image, axis=0)
|
14 |
-
|
15 |
-
def predict(image):
|
16 |
-
input_array = preprocess(image)
|
17 |
-
prediction = model.predict(input_array)[0][0]
|
18 |
-
label = "NORMAL" if prediction >= 0.5 else "ABNORMAL"
|
19 |
-
confidence = prediction if label == "NORMAL" else 1 - prediction
|
20 |
-
|
21 |
-
if label == "NORMAL" and confidence >= 0.7:
|
22 |
-
explanation = "✅ The kidney CT scan appears normal with high confidence."
|
23 |
-
attention_flag = ""
|
24 |
-
elif label == "NORMAL" and confidence < 0.7:
|
25 |
-
explanation = "⚠️ The scan appears normal, but the model's confidence is low. Consider radiologist review."
|
26 |
-
attention_flag = "🚨 FLAGGED FOR RADIOLOGIST REVIEW"
|
27 |
-
else:
|
28 |
-
explanation = "⚠️ The kidney CT scan shows signs of abnormality. Immediate radiologist attention is recommended."
|
29 |
-
attention_flag = "🚨 FLAGGED FOR RADIOLOGIST REVIEW"
|
30 |
-
|
31 |
-
return f""" Prediction: {label}
|
32 |
-
🔎 Confidence: {confidence:.2%}
|
33 |
-
|
34 |
-
{explanation}
|
35 |
-
{attention_flag}"""
|
36 |
-
|
37 |
-
demo = gr.Interface(
|
38 |
-
fn=predict,
|
39 |
-
inputs=gr.Image(type="pil"),
|
40 |
-
outputs="text",
|
41 |
-
title="Kidney CT Classifier",
|
42 |
-
description="Upload a kidney CT image. The model will predict if it's NORMAL or ABNORMAL. Flagged results go to radiologist review.",
|
43 |
-
examples=["images/sample1.png", "images/sample2.png"]
|
44 |
-
)
|
45 |
-
|
46 |
-
if __name__ == "__main__":
|
47 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|