File size: 853 Bytes
bbf3a3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image

CLASS_NAMES = [
    "MildDemented",
    "Moderate Dementia",
    "NonDemented",
    "Very mild Dementia",
    "glioma",
    "meningioma",
    "notumor",
    "pituitary"
]

# Load model locally in the Space
model = tf.keras.models.load_model("alz_classifier.keras")

def predict_mri(img):
    img = img.resize((128,128))
    x = np.array(img)/255.0
    x = np.expand_dims(x, axis=0)
    
    preds = model.predict(x)
    pred_class = CLASS_NAMES[np.argmax(preds)]
    return {pred_class: float(np.max(preds))}

demo = gr.Interface(
    fn=predict_mri,
    inputs=gr.Image(type="pil"),
    outputs=gr.Label(num_top_classes=1),
    title="Alzheimer & Brain Tumor 8-Class MRI Classifier",
    description="Upload an MRI image to classify into 8 classes."
)

demo.launch()