File size: 711 Bytes
5abf6fa
 
ac27e3e
5abf6fa
 
f0e26a3
5abf6fa
 
 
 
 
 
 
 
 
 
 
 
ac27e3e
5abf6fa
ac27e3e
5abf6fa
f0e26a3
5abf6fa
f0e26a3
 
5abf6fa
f0e26a3
5abf6fa
f0e26a3
 
5abf6fa
f0e26a3
5abf6fa
f0e26a3
5abf6fa
 
 
ac27e3e
5abf6fa
 
 
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
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image

model = tf.keras.models.load_model("brain_mri_model.keras")

class_names = [
"MildDemented",
"ModerateDementia",
"NonDemented",
"VeryMildDementia",
"Glioma",
"Meningioma",
"NoTumor",
"Pituitary"
]

IMG_SIZE = (224,224)

def predict(image):

    img = image.resize(IMG_SIZE)

    img = np.array(img)/255.0
    img = np.expand_dims(img,0)

    pred = model.predict(img)

    idx = np.argmax(pred)
    conf = np.max(pred)

    return f"{class_names[idx]} | Confidence: {conf:.2f}"

demo = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="pil"),
    outputs="text",
    title="Brain MRI Disease Detection"
)

demo.launch()