File size: 1,760 Bytes
158e581
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from tensorflow.keras.models import load_model
import numpy as np
from PIL import Image

# Load model from Hugging Face model repository
model = load_model("https://huggingface.co/syaha/skin_cancer_detection_model/resolve/main/skin_cancer_detection_model.h5")

# Preprocess function
def preprocess_image(image):
    image = image.resize((224, 224))  # Resize to match model input size
    image = np.array(image) / 255.0  # Normalize
    image = np.expand_dims(image, axis=0)  # Add batch dimension
    return image

# Predict function
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 information mapping
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.'}
}

# Gradio interface
iface = gr.Interface(fn=predict_image, inputs="image", outputs="text")
iface.launch()