|
import gradio as gr |
|
import numpy as np |
|
from PIL import Image |
|
import cv2 |
|
import tensorflow as tf |
|
|
|
|
|
model = tf.keras.models.load_model("effnet.h5") |
|
|
|
def img_pred(upload): |
|
|
|
opencvImage = cv2.cvtColor(np.array(upload), cv2.COLOR_RGB2BGR) |
|
img = cv2.resize(opencvImage, (150, 150)) |
|
img = img.reshape(1, 150, 150, 3) |
|
|
|
|
|
p = model.predict(img) |
|
p = np.argmax(p, axis=1)[0] |
|
|
|
|
|
if p == 0: |
|
result = 'Glioma Tumor' |
|
elif p == 1: |
|
result = 'No Tumor' |
|
elif p == 2: |
|
result = 'Meningioma Tumor' |
|
else: |
|
result = 'Pituitary Tumor' |
|
|
|
return f'The Model predicts: {result}' |
|
|
|
|
|
iface = gr.Interface( |
|
fn=img_pred, |
|
inputs=gr.Image(type="pil"), |
|
outputs="text", |
|
title="Brain Tumor Detection", |
|
description="Upload an MRI image to check if there is a tumor and determine the type if detected." |
|
) |
|
|
|
|
|
iface.launch() |
|
|