BTDL / app.py
Gajendra5490's picture
Rename App.py to app.py
d650723 verified
import gradio as gr
from tensorflow.keras.models import load_model
import cv2
import numpy as np
# Load the trained model
model = load_model("classifier-resnet.keras")
def preprocess_image(image):
"""Preprocess the input image for model prediction"""
img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # Convert to RGB
img = cv2.resize(img, (256, 256)) # Resize to match model input shape
img = img / 255.0 # Normalize pixel values (0-1)
img = np.expand_dims(img, axis=0) # Add batch dimension
return img
def predict(image):
"""Predict if the image contains a brain tumor"""
img = preprocess_image(image)
pred = model.predict(img)
result = "🧠 Tumor Detected" if pred[0][0] > 0.5 else "✅ No Tumor Detected"
return result
# Create Gradio Interface
interface = gr.Interface(
fn=predict,
inputs=gr.Image(type="numpy"),
outputs="text",
title="Brain Tumor Detection",
description="Upload an MRI scan to detect brain tumors."
)
# Launch the Gradio app
interface.launch()