|
import gradio as gr |
|
from PIL import Image |
|
import numpy as np |
|
from tensorflow.keras.preprocessing import image as keras_image |
|
from tensorflow.keras.applications.resnet50 import preprocess_input |
|
from tensorflow.keras.models import load_model |
|
|
|
|
|
model = load_model('model.h5') |
|
|
|
def predict_alzheimer(img): |
|
img = Image.fromarray(img.astype('uint8'), 'RGB') |
|
img = img.resize((224, 224)) |
|
img_array = keras_image.img_to_array(img) |
|
img_array = np.expand_dims(img_array, axis=0) |
|
img_array = preprocess_input(img_array) |
|
|
|
prediction = model.predict(img_array) |
|
classes = ['Mild Demented', 'Non Demented', 'Very Mild Demented' ] |
|
return {classes[i]: float(prediction[0][i]) for i in range(3)} |
|
|
|
|
|
interface = gr.Interface(fn=predict_alzheimer, |
|
inputs="image", |
|
outputs="label", |
|
title="Alzheimer Classifier", |
|
description="Upload an image of a CT of a brain and the classifier will predict between a mild demented, non demetend and very mild demtened alzheimer") |
|
|
|
|
|
interface.launch() |
|
|