onlyshrey98 commited on
Commit
8a11042
·
verified ·
1 Parent(s): 2d531a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -3,16 +3,16 @@ import tensorflow as tf
3
  import numpy as np
4
  from PIL import Image
5
 
6
- # Load the trained Pap Smear model
7
  model = tf.keras.models.load_model("papsmear-test_model.h5")
8
 
9
- # Threshold for classification
10
  THRESHOLD = 0.5
11
 
12
- # Preprocessing function (modify if your model used different preprocessing)
13
  def preprocess_image(img):
14
- img = img.resize((224, 224)) # resize as per your model’s input size
15
- img = np.array(img) / 255.0 # normalize
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 = f"Confidence: {prediction:.3f}"
27
  else:
28
  label = "✅ Negative (Normal Pap Smear)"
29
- confidence = f"Confidence: {1 - prediction:.3f}"
30
 
31
- return {label: float(prediction)} if prediction > THRESHOLD else {label: float(1 - prediction)}
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__":