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()