File size: 1,160 Bytes
e4321c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57e5c66
e4321c7
 
30e0427
e4321c7
 
8b3ecea
e4321c7
 
8b3ecea
e4321c7
 
 
 
 
 
6caf678
8967e87
 
ccefb8e
 
 
 
 
 
8967e87
e4321c7
 
 
 
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
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):
    img = img/255
    img = tf.image.resize(img, [224, 224])
    img = np.expand_dims(img, axis=0)

    my_model = load_model('chest_model.h5')

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

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

    # Return the binary prediction
    return binary_prediction

# Define Gradio interface
iface = gr.Interface(
    fn=predict_input_image,
    inputs=gr.Image(),
    outputs='text',
    allow_flagging = 'manual',
    flagging_dir = 'Elegbede/Pneumonia_Detection/flagged',
    examples= [
        ['Pneumonia_01.jpeg'],
        ['Pneumonia_02.jpeg'],
        ['Pneumonia_03.jpeg'],
        ['Normal_01.jpeg'],
        ['Normal_02.jpeg'],
        ['Normal_03.jpeg']
    ]
)

# Launch the interface
iface.launch()