Spaces:
Runtime error
Runtime error
import gradio as gr | |
# from transformers import pipeline | |
import numpy as np | |
from PIL import Image | |
import tensorflow as tf | |
model = tf.keras.models.load_model("/content/model1_acc96_kera.h5") | |
# Function to preprocess the image and make predictions | |
def classify_alzheimers_image(input_image): | |
try: | |
# Preprocess the image (resize, normalize, etc.) | |
input_image = np.array(input_image) | |
input_image_copy = input_image.copy() # Making a copy to avoid the array reference issue | |
input_image_resized = np.array(Image.fromarray(input_image_copy).resize((128, 128))) / 255.0 | |
input_image_resized = np.expand_dims(input_image_resized, axis=0) | |
# Making predictions | |
predictions = model.predict(input_image_resized) | |
# Getting the class with the highest probability | |
class_idx = np.argmax(predictions) | |
class_label = ["Mild Demented", "Moderate Demented", "Non-Demented", "Very Mild Demented"][class_idx] | |
confidence = predictions[0][class_idx] | |
return f"Prediction: {class_label}, Confidence: {confidence:.2f}" | |
except Exception as e: | |
return str(e) | |
# Creating a Gradio interface | |
iface = gr.Interface( | |
fn=classify_alzheimers_image, | |
inputs="image", | |
outputs="text", | |
title="Alzheimer's Disease Classification", | |
description=" Upload an MRI Image for classification.", | |
flagging_options = ["Wrong Prediction"], | |
theme = 'darkhuggingface' | |
) | |
# Launching the Gradio interface | |
iface.launch(inline = False) | |