Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,16 +3,16 @@ import tensorflow as tf
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
model = tf.keras.models.load_model("papsmear-test_model.h5")
|
| 8 |
|
| 9 |
-
#
|
| 10 |
THRESHOLD = 0.5
|
| 11 |
|
| 12 |
-
# Preprocessing function
|
| 13 |
def preprocess_image(img):
|
| 14 |
-
img = img.resize((224, 224)) #
|
| 15 |
-
img = np.array(img) / 255.0
|
| 16 |
img = np.expand_dims(img, axis=0)
|
| 17 |
return img
|
| 18 |
|
|
@@ -23,12 +23,12 @@ def classify_image(image):
|
|
| 23 |
|
| 24 |
if prediction > THRESHOLD:
|
| 25 |
label = "🩸 Positive (Possible Abnormality Detected)"
|
| 26 |
-
confidence =
|
| 27 |
else:
|
| 28 |
label = "✅ Negative (Normal Pap Smear)"
|
| 29 |
-
confidence =
|
| 30 |
|
| 31 |
-
return {label: float(
|
| 32 |
|
| 33 |
# Gradio Interface
|
| 34 |
demo = gr.Interface(
|
|
@@ -37,10 +37,6 @@ demo = gr.Interface(
|
|
| 37 |
outputs=gr.Label(num_top_classes=1, label="Classification Result"),
|
| 38 |
title="Pap Smear Test Analyzer 🧫",
|
| 39 |
description="Upload a Pap smear image to classify whether it is Normal (Negative) or Abnormal (Positive).",
|
| 40 |
-
examples=[
|
| 41 |
-
["example_papsmear_normal.jpg"],
|
| 42 |
-
["example_papsmear_positive.jpg"]
|
| 43 |
-
]
|
| 44 |
)
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
+
# Load your Pap Smear model
|
| 7 |
model = tf.keras.models.load_model("papsmear-test_model.h5")
|
| 8 |
|
| 9 |
+
# Optimal threshold
|
| 10 |
THRESHOLD = 0.5
|
| 11 |
|
| 12 |
+
# Preprocessing function
|
| 13 |
def preprocess_image(img):
|
| 14 |
+
img = img.resize((224, 224)) # adjust if your model uses a different size
|
| 15 |
+
img = np.array(img) / 255.0
|
| 16 |
img = np.expand_dims(img, axis=0)
|
| 17 |
return img
|
| 18 |
|
|
|
|
| 23 |
|
| 24 |
if prediction > THRESHOLD:
|
| 25 |
label = "🩸 Positive (Possible Abnormality Detected)"
|
| 26 |
+
confidence = prediction
|
| 27 |
else:
|
| 28 |
label = "✅ Negative (Normal Pap Smear)"
|
| 29 |
+
confidence = 1 - prediction
|
| 30 |
|
| 31 |
+
return {label: float(confidence)}
|
| 32 |
|
| 33 |
# Gradio Interface
|
| 34 |
demo = gr.Interface(
|
|
|
|
| 37 |
outputs=gr.Label(num_top_classes=1, label="Classification Result"),
|
| 38 |
title="Pap Smear Test Analyzer 🧫",
|
| 39 |
description="Upload a Pap smear image to classify whether it is Normal (Negative) or Abnormal (Positive).",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
)
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|