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()