Spaces:
Runtime error
Runtime error
File size: 1,520 Bytes
0cb7b54 |
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 43 44 45 |
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)
|