File size: 1,742 Bytes
728c950
e8d8efc
9018b21
e8d8efc
5d4283b
9f784aa
 
 
 
9018b21
 
 
 
728c950
8aa6871
5d4283b
9f784aa
 
 
 
 
 
 
 
 
5d4283b
9f784aa
728c950
9f784aa
 
 
 
 
 
 
 
 
728c950
9f784aa
728c950
9f784aa
728c950
 
 
 
9f784aa
728c950
 
 
 
 
 
 
9f784aa
 
 
728c950
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import gradio as gr
from keras.models import load_model
from huggingface_hub import hf_hub_download
from PIL import Image
import numpy as np

# -------------------------------
# MODEL LOADING
# -------------------------------
MODEL_PATH = hf_hub_download(
    repo_id="aadityaramrame/blood-cell-cancer-detector",
    filename="cancer_classifier.h5"
)

model = load_model(MODEL_PATH)

# Class mapping
CLASSES = [
    "platelet",
    "monocyte",
    "lymphocyte",
    "erythroblast",
    "eosinophil",
    "basophil"
]

# -------------------------------
# PREDICTION FUNCTION
# -------------------------------
def classify_cancer(image):
    try:
        image = image.convert("RGB").resize((224, 224))
        img_array = np.expand_dims(np.array(image) / 255.0, axis=0)
        prediction = model.predict(img_array)
        predicted_class = int(np.argmax(prediction))
        confidence = float(np.max(prediction))
        label = CLASSES[predicted_class]
        return f"🧫 **Predicted Cell Type:** {label}\n📊 **Confidence:** {confidence:.3f}"
    except Exception as e:
        return f"⚠️ Error: {str(e)}"

# -------------------------------
# GRADIO INTERFACE
# -------------------------------
demo = gr.Interface(
    fn=classify_cancer,
    inputs=gr.Image(type="pil", label="📸 Upload Blood Cell Image"),
    outputs=gr.Markdown(label="Result"),
    title="🧬 Blood Cell Cancer Detection",
    description=(
        "Upload a blood cell image to classify its type using a trained CNN model.\n"
        "Model trained on microscopic blood cell images for cancer detection."
    ),
    theme="soft"
)

# -------------------------------
# LAUNCH
# -------------------------------
if __name__ == "__main__":
    demo.launch()