import gradio as gr from tensorflow.keras.models import load_model from tensorflow.keras.preprocessing import image import numpy as np # Load the model model = load_model('skin_cancer_model.h5') # Mapping class index to class name class_names = ['akiec', 'bcc', 'bkl', 'df', 'nv', 'vasc', 'mel'] def predict_skin_cancer(img): # Preprocess the image img = img.resize((224, 224)) img_array = np.array(img) / 255.0 img_array = np.expand_dims(img_array, axis=0) # Make prediction predictions = model.predict(img_array) predicted_class = np.argmax(predictions, axis=1)[0] # Return the class name return f"Predicted class: {class_names[predicted_class]}" # Create a Gradio interface interface = gr.Interface( fn=predict_skin_cancer, inputs=gr.Image(type="pil", label="Upload Skin Lesion Image"), outputs="text", title="Skin Cancer Prediction", description="Upload an image of a skin lesion to predict its class.", ) # Launch the app interface.launch()