Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Load the trained model
|
| 7 |
+
model = tf.keras.models.load_model("cancer_classifier.h5")
|
| 8 |
+
|
| 9 |
+
# Define the class names (make sure they match your dataset)
|
| 10 |
+
class_names = ['Basophil', 'Eosinophil', 'Erythroblast', 'IG', 'lymphocyte', 'Monocyte', 'Neutrophil', 'Platelet']
|
| 11 |
+
|
| 12 |
+
# Define prediction function
|
| 13 |
+
def predict(image):
|
| 14 |
+
image = image.resize((224, 224))
|
| 15 |
+
img_array = np.array(image) / 255.0
|
| 16 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 17 |
+
|
| 18 |
+
prediction = model.predict(img_array)
|
| 19 |
+
class_index = np.argmax(prediction)
|
| 20 |
+
confidence = float(np.max(prediction))
|
| 21 |
+
|
| 22 |
+
return {
|
| 23 |
+
"Predicted Class": class_names[class_index],
|
| 24 |
+
"Confidence": round(confidence * 100, 2)
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
# Gradio interface
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=predict,
|
| 30 |
+
inputs=gr.Image(type="pil", label="Upload Blood Cell Image"),
|
| 31 |
+
outputs=[
|
| 32 |
+
gr.Label(label="Prediction"),
|
| 33 |
+
],
|
| 34 |
+
title="🧬 Blood Cell Cancer Classifier",
|
| 35 |
+
description="Upload a blood cell image to classify whether it's cancerous or not using a fine-tuned EfficientNetB3 model.",
|
| 36 |
+
theme="gradio/soft"
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
iface.launch()
|