|
|
import gradio as gr |
|
|
import tensorflow as tf |
|
|
import numpy as np |
|
|
from PIL import Image |
|
|
|
|
|
|
|
|
model = tf.keras.models.load_model("brain_tumor_model.h5") |
|
|
|
|
|
|
|
|
def predict_tumor(image): |
|
|
image = image.resize((150, 150)) |
|
|
image = np.expand_dims(np.array(image) / 255.0, axis=0) |
|
|
prediction = model.predict(image)[0][0] |
|
|
return "🧠 Tumor Detected" if prediction > 0.5 else "✅ No Tumor Detected" |
|
|
|
|
|
|
|
|
gr.Interface( |
|
|
fn=predict_tumor, |
|
|
inputs=gr.Image(type="pil"), |
|
|
outputs="text", |
|
|
title="🧠 Brain Tumor MRI Classifier", |
|
|
description="Upload a brain MRI scan to detect tumor presence.", |
|
|
allow_flagging="never" |
|
|
).launch() |
|
|
|