File size: 1,292 Bytes
4c4b26c
 
 
 
3547f56
4c4b26c
 
 
 
 
 
 
 
 
2cea944
4c4b26c
 
66a2215
 
 
4c4b26c
 
2cea944
4c4b26c
2cea944
4c4b26c
66a2215
03082bc
2cea944
4c4b26c
66a2215
4940ea7
66a2215
4c4b26c
4940ea7
 
 
 
 
 
 
0cb108c
4940ea7
 
0cb108c
4940ea7
 
 
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
49
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model


# Load the trained model
model = load_model('skin_model.h5')

# Define a function to make predictions
def predict(image):
    # Preprocess the image
    image = image / 255.0
    image = np.expand_dims(image, axis=0)
    
    # Make a prediction using the model
    prediction = model.predict(image)
    
    # Get the sigmoid percentage
    sigmoid_percentage = prediction[0][0] * 100
    
    # Get the predicted class label
    if prediction[0][0] < 0.5:
        label = 'Benign'
    else:
        label = 'Malignant'
    
    return f"{label} ({sigmoid_percentage:.2f}%)"

examples = [["benign.jpg"], ["malignant.jpg"]]

# Define input and output components
image_input = gr.inputs.Image(shape=(150, 150))
label_output = gr.outputs.Label()

# Define a Gradio interface for user interaction
iface = gr.Interface(
    fn=predict,
    inputs=image_input,
    outputs=label_output,
    examples=examples,
    title="Skin Cancer Classification",
    description="Predicts whether a Skin Lesion is Cancerous or not.",
    theme="default",  # Choose a theme: "default", "compact", "huggingface"
    layout="vertical",  # Choose a layout: "vertical", "horizontal", "double"
    live=False 
)

iface.launch()