Spaces:
Sleeping
Sleeping
| 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() | |