|
import gradio as gr |
|
import numpy as np |
|
from PIL import Image |
|
import cv2 |
|
import tensorflow as tf |
|
|
|
|
|
model = tf.keras.models.load_model("Brain_tumor_pred_large.h5") |
|
|
|
def img_pred(upload): |
|
|
|
opencvImage = cv2.cvtColor(np.array(upload), cv2.COLOR_RGB2BGR) |
|
img = cv2.resize(opencvImage, (128, 128)) |
|
img = img.reshape(1, 128, 128, 3) |
|
|
|
|
|
predictions = model.predict(img)[0] |
|
predicted_class = np.argmax(predictions) |
|
confidence = predictions[predicted_class] |
|
|
|
|
|
if confidence < 0.20: |
|
if confidence <0.10: |
|
result="No Tumor" |
|
confidence=1 |
|
else: |
|
result = "Uncertain" |
|
else: |
|
if predicted_class == 1: |
|
result = "No Tumor" |
|
else: |
|
result = "Tumor Detected" |
|
|
|
|
|
return f"The Model predicts: {result} with a confidence of {confidence:.2%}" |
|
|
|
|
|
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(share=True) |
|
|