File size: 1,233 Bytes
97644d9
 
 
 
 
8a11042
97644d9
 
8a11042
97644d9
 
8a11042
97644d9
8a11042
 
97644d9
 
 
 
 
 
 
 
 
 
8a11042
97644d9
 
8a11042
97644d9
8a11042
97644d9
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image

# Load your Pap Smear model
model = tf.keras.models.load_model("papsmear-test_model.h5")

# Optimal threshold
THRESHOLD = 0.5

# Preprocessing function
def preprocess_image(img):
    img = img.resize((224, 224))  # adjust if your model uses a different size
    img = np.array(img) / 255.0
    img = np.expand_dims(img, axis=0)
    return img

# Prediction function
def classify_image(image):
    processed = preprocess_image(image)
    prediction = model.predict(processed)[0][0]

    if prediction > THRESHOLD:
        label = "🩸 Positive (Possible Abnormality Detected)"
        confidence = prediction
    else:
        label = "✅ Negative (Normal Pap Smear)"
        confidence = 1 - prediction

    return {label: float(confidence)}

# Gradio Interface
demo = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type="pil", label="Upload Pap Smear Image"),
    outputs=gr.Label(num_top_classes=1, label="Classification Result"),
    title="Pap Smear Test Analyzer 🧫",
    description="Upload a Pap smear image to classify whether it is Normal (Negative) or Abnormal (Positive).",
)

if __name__ == "__main__":
    demo.launch()