File size: 1,232 Bytes
c7e8622
 
c662a40
c7e8622
5d729a7
 
c7e8622
a70b7b1
abe5204
3e2a740
 
 
 
edc2516
ec7fc58
abe5204
c476e3f
 
 
 
 
abe5204
6462de4
abe5204
 
857a10e
35fa410
5d729a7
857a10e
c662a40
671b81e
 
 
5d729a7
 
95405ab
 
 
 
 
 
 
 
671b81e
c7e8622
671b81e
1b96c12
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
import gradio as gr
import tensorflow as tf
from tensorflow.keras.models import load_model
import numpy as np
from PIL import Image
import io

def predict_input_image(img):
    # Normalize the image by cropping (center crop)
    h, w = img.shape[:2]
    crop_start_x = (w - 224) // 2
    crop_start_y = (h - 224) // 2
    img = img[crop_start_y:crop_start_y+224, crop_start_x:crop_start_x+224]
    img = tf.image.resize(img, [224, 224])
    img = np.expand_dims(img, axis=0)

    my_model = load_model('Brain_Tumor_Model.h5')

    # Set a threshold for binary classification
    threshold = 0.5
    
    # Make predictions using your model
    predictions = my_model.predict(img)

    # Convert predictions to binary (0 or 1) based on the threshold
    binary_prediction = 'Tumor Detected' if predictions[0][0] > threshold else 'No Tumor Detected'

    # Return the binary prediction
    return binary_prediction

# Define Gradio interface
iface = gr.Interface(
    fn=predict_input_image,
    inputs=gr.Image(),
    outputs='text',
    examples = [
        ['G_101.jpg'],
        ['N_10.jpg'],
        ['M_107.jpg'],
        ['N_101.jpg'],
        ['M_119.jpg'],
        ['N_128.jpg']
    ]
)

# Launch the interface
iface.launch()