File size: 1,337 Bytes
7a8084d
 
 
3301b3c
7a8084d
 
3301b3c
7a8084d
 
3301b3c
7a8084d
 
3301b3c
 
 
 
 
 
 
 
7a8084d
3301b3c
7a8084d
3301b3c
 
7a8084d
3301b3c
 
7a8084d
3301b3c
29be643
 
 
 
 
7a8084d
 
 
 
 
 
3301b3c
7a8084d
3301b3c
7a8084d
 
 
09356b9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import gradio as gr
import numpy as np
import tensorflow as tf
from PIL import Image

# Load the trained model
model = tf.keras.models.load_model("BRAIINTUMORMODEL.h5")

# Define class labels
class_labels = ["Glioma", "Meningioma", "No Tumor", "Pituitary"]

def predict_brain_tumor(img):
    # Convert to RGB if needed
    if img.mode != 'RGB':
        img = img.convert('RGB')
    
    # Preprocess image
    img = img.resize((224, 224))
    img_array = np.array(img) / 255.0
    img_array = np.expand_dims(img_array, axis=0)

    # Make prediction
    prediction = model.predict(img_array)[0]
    predicted_class = np.argmax(prediction)
    confidence = np.max(prediction) * 100
    
    # Format output
    return f"Predicted Tumor Type: {class_labels[predicted_class]} (Confidence: {confidence:.2f}%)"

# Example images
example_images = [
    ["example_glioma.jpg"],
    ["example_meningioma.jpeg"],
    ["example_notumor.jpeg"],
    ["example_pit.jpg"] 
]

# Create Gradio Interface
iface = gr.Interface(
    fn=predict_brain_tumor,
    inputs=gr.Image(type="pil"),
    outputs=gr.Textbox(label="Prediction Result"),
    title="🧠 Brain Tumor Classification",
    description="Upload an MRI image to classify the tumor type. You can also click on the example images below.",
    examples=example_images
)

iface.launch(share=True)