File size: 1,203 Bytes
eebd2c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import numpy as np
from PIL import Image
import tensorflow as tf
from keras.preprocessing import image
from keras.models import load_model

# Load the trained model
model_path = 'SCDSNet-H10K_Model-1.keras'
model = load_model(model_path)

# Define the class labels
classes = ['akiec', 'bcc', 'bkl', 'df', 'melanoma', 'nv', 'vasc']

# Function to preprocess the image
def preprocess_image(image_bytes):
    img = Image.open(image_bytes).convert('RGB')
    img = img.resize((32, 32))
    img_array = image.img_to_array(img)
    img_array = np.expand_dims(img_array, axis=0)
    img_array = img_array / 255.0
    return img_array

# Function to predict class label and probability
def predict_image(image_bytes):
    img_array = preprocess_image(image_bytes)
    predictions = model.predict(img_array)
    score = tf.nn.softmax(predictions[0])
    predicted_class = classes[np.argmax(score)]
    return predicted_class

# Create a Gradio interface
iface = gr.Interface(
    fn=predict_image, 
    inputs="file",
    outputs=["label"],
    title="Skin Cancer Classification",
    description="Upload an image of a skin lesion for classification."
)

# Launch the interface
iface.launch()