|
import gradio as gr |
|
import numpy as np |
|
from PIL import Image |
|
from keras.models import load_model |
|
|
|
|
|
model = load_model('brain_tumor_model.h5') |
|
|
|
|
|
def predict_image(image): |
|
|
|
img = image.resize((128, 128)) |
|
|
|
|
|
img = np.array(img) |
|
|
|
|
|
if img.shape == (128, 128): |
|
img = np.stack((img,) * 3, axis=-1) |
|
|
|
|
|
img = np.expand_dims(img, axis=0) |
|
|
|
|
|
prediction = model.predict(img) |
|
|
|
|
|
predicted_class = np.argmax(prediction) |
|
confidence = np.max(prediction) |
|
|
|
|
|
if predicted_class == 0: |
|
return f'No tumor detected. Confidence: {confidence:.2f}' |
|
else: |
|
return f'Tumor detected. Confidence: {confidence:.2f}' |
|
|
|
|
|
css = """ |
|
body { |
|
background-color: #f0f4f7; |
|
} |
|
""" |
|
|
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_image, |
|
inputs=gr.Image(type="pil"), |
|
outputs=gr.Textbox(), |
|
title="Brain Tumor Detection AI App", |
|
description="Upload a Magnetic Resonance Imaging (MRI) scan image to detect brain tumors.", |
|
css=css, |
|
|
|
flagging_options=["Incorrect Diagnosis", "Image Not Clear", "Model Error"], |
|
) |
|
|
|
|
|
iface.launch() |