multimodality / app.py
Amimul A Hasan RofiK
Update app.py
f0e26a3 verified
Raw
History Blame Contribute Delete
711 Bytes
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()