Update app.py
Browse files
app.py
CHANGED
|
@@ -41,8 +41,11 @@ transform = transforms.Compose([
|
|
| 41 |
# Predict and save
|
| 42 |
def predict_retinopathy(image):
|
| 43 |
# Validate image
|
| 44 |
-
|
| 45 |
-
return
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 48 |
img = image.convert("RGB").resize((224, 224))
|
|
@@ -67,7 +70,10 @@ def predict_retinopathy(image):
|
|
| 67 |
filename = f"{timestamp}_{label}_{confidence:.2f}.png"
|
| 68 |
cam_pil.save(os.path.join(save_dir, filename))
|
| 69 |
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
# Gradio app
|
| 73 |
gr.Interface(
|
|
|
|
| 41 |
# Predict and save
|
| 42 |
def predict_retinopathy(image):
|
| 43 |
# Validate image
|
| 44 |
+
if not looks_like_fundus(image):
|
| 45 |
+
return (
|
| 46 |
+
invalid_img,
|
| 47 |
+
"❌ Invalid image detected.\n\nPlease upload a *retinal fundus scan* for accurate Diabetic Retinopathy assessment."
|
| 48 |
+
)
|
| 49 |
|
| 50 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 51 |
img = image.convert("RGB").resize((224, 224))
|
|
|
|
| 70 |
filename = f"{timestamp}_{label}_{confidence:.2f}.png"
|
| 71 |
cam_pil.save(os.path.join(save_dir, filename))
|
| 72 |
|
| 73 |
+
return (
|
| 74 |
+
cam_pil,
|
| 75 |
+
f"{label} (Confidence: {confidence:.2f})"
|
| 76 |
+
)
|
| 77 |
|
| 78 |
# Gradio app
|
| 79 |
gr.Interface(
|