File size: 1,203 Bytes
c7e8622
 
78d872d
c7e8622
1658bdc
78d872d
 
 
 
 
 
 
 
 
44a0236
78d872d
 
 
 
 
 
 
 
 
 
c7e8622
a70b7b1
78d872d
 
 
 
44a0236
78d872d
 
af1629d
78d872d
35fa410
671b81e
f14de50
671b81e
 
 
78d872d
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
48
import gradio as gr
import tensorflow as tf
import cv2
import numpy as np

def preprocess_image(img):
    # Resize the image to the target size (256x256)
    img = cv2.resize(img, (256, 256))
    
    # Center crop to 224x224
    h, w, _ = img.shape
    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]

    # Normalize the image
    img = img / 255.0
    
    # Convert BGR to RGB
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    
    # Expand dimensions to match model input shape
    img = np.expand_dims(img, axis=0)
    
    return img

def predict_input_image(img):
    # Preprocess the input image
    img = preprocess_image(img)

    # Load the pre-trained model
    model = tf.keras.models.load_model('Tumor_Model.h5')

    # Make predictions
    prediction = model.predict(img)
    result = 'No Tumor Detected' if prediction[0][0] > 0.5 else 'Tumor detected'

    return f"Prediction: {result}"

# Define Gradio interface
iface = gr.Interface(
    fn=predict_input_image,
    inputs=gr.Image(type="numpy", preprocess=preprocess_image),
    outputs="text",
)

# Launch the interface
iface.launch()