|
import gradio as gr |
|
from tensorflow.keras.models import load_model |
|
import numpy as np |
|
from PIL import Image |
|
|
|
|
|
model = load_model("syaha/skin_cancer_detection_model") |
|
|
|
|
|
def preprocess_image(image): |
|
image = image.resize((224, 224)) |
|
image = np.array(image) / 255.0 |
|
image = np.expand_dims(image, axis=0) |
|
return image |
|
|
|
|
|
def predict_image(image): |
|
img = preprocess_image(image) |
|
prediction = model.predict(img) |
|
predicted_class = np.argmax(prediction, axis=1)[0] |
|
|
|
class_label = disease_info[predicted_class]['name'] |
|
description = disease_info[predicted_class]['description'] |
|
|
|
return f"Prediction: {class_label}\nDescription: {description}" |
|
|
|
|
|
disease_info = { |
|
0: {'name': 'Actinic Keratoses (akiec)', 'description': 'Rough, scaly patches caused by sun exposure.'}, |
|
1: {'name': 'Basal Cell Carcinoma (bcc)', 'description': 'A type of skin cancer that rarely spreads.'}, |
|
2: {'name': 'Benign Keratosis (bkl)', 'description': 'Non-cancerous skin lesions.'}, |
|
3: {'name': 'Dermatofibroma (df)', 'description': 'A benign lesion often on the legs.'}, |
|
4: {'name': 'Melanocytic Nevus (nv)', 'description': 'Common mole, can develop into melanoma.'}, |
|
5: {'name': 'Vascular Lesions (vasc)', 'description': 'Blood vessel-related skin growths.'}, |
|
6: {'name': 'Melanoma (mel)', 'description': 'Most dangerous skin cancer, early detection is key.'} |
|
} |
|
|
|
|
|
iface = gr.Interface(fn=predict_image, inputs="image", outputs="text") |
|
iface.launch() |