File size: 1,391 Bytes
689e5f5
eacff3c
 
 
 
 
a803ac2
eacff3c
689e5f5
0a2443d
 
 
 
689e5f5
 
 
 
 
 
 
 
 
c7154a6
fdb58ce
c7154a6
 
689e5f5
 
 
 
bbe16a1
c7154a6
689e5f5
 
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
# this is the custome function to return pre-process the image to size (150 150 3)

import numpy as np
from tensorflow.keras.preprocessing import image 
from PIL import Image
import gradio as gr
from keras.models import load_model

def custom_Image_preprocessing(image_data, target_size=(150, 150)):
    img = image.array_to_img(image_data, data_format='channels_last')
    img = img.resize(target_size)  # Resize the image if needed
    img_arr = image.img_to_array(img)
    img_arr = img_arr * 1./255
    img_arr = np.expand_dims(img_arr, axis=0)
    return img_arr

# function to predict the custome image

def image_predict(image_path):
    model = load_model("Second_model.h5")
    image_preprocess = custom_Image_preprocessing(image_path)
    result = model.predict(image_preprocess)
    if ( result <= 0.5  ):
        return 'Negative',round(result[0][0]*100,2),'%'
    else:
        return 'Positive',round(result[0][0]*100,2),'%'


# Define Gradio interface
input_component =  gr.components.Image(label = "Upload the X-Ray")
output_component = gr.components.Textbox(label = "Result")
interface = gr.Interface(fn=image_predict, inputs=input_component, outputs=output_component,title = "Lung Cancer x-Ray Classification",description = "This web app provides predictions based on X-Ray images and predict either the X-ray contains sympotms of lung cancer or not ")
interface.launch()