Spaces:
Runtime error
Runtime error
import gradio as gr | |
import joblib | |
from keras.preprocessing import image | |
import numpy as np | |
# Load the model using joblib | |
model = joblib.load("./your_model.pkl") | |
# Define a function to preprocess an image | |
def preprocess_image(image_path, target_size=(128, 128)): | |
img = image.load_img(image_path, target_size=target_size) | |
img_array = image.img_to_array(img) | |
img_array = np.expand_dims(img_array, axis=0) | |
img_array /= 255.0 # Normalize | |
return img_array | |
# Define a prediction function for Gradio | |
def classify_skin_cancer(image): | |
image_path = "uploaded_image.jpg" | |
image.save(image_path) | |
# Preprocess the image | |
processed_image = preprocess_image(image_path) | |
# Make a prediction using the model | |
prediction = model.predict(processed_image) | |
result = "Malignant" if prediction[0][0] > 0.5 else "Benign" | |
return result | |
# Create a Gradio interface | |
iface = gr.Interface( | |
fn=classify_skin_cancer, | |
inputs=gr.inputs.Image(type="pil", label="Upload a skin image"), | |
outputs="text", | |
live=True, | |
title="Skin Cancer Classifier", | |
description="Upload a skin image and get a classification result (Malignant or Benign)." | |
) | |
if __name__ == "__main__": | |
iface.launch() | |