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

model = load_model("skin_cancer_detection_model.h5")

def predict_image(image):
    img = tf.image.resize(image, (224, 224))
    img = np.expand_dims(img, axis=0)
    img = img / 255.0

    prediction = model.predict(img)
    predicted_class = np.argmax(prediction, axis=1)[0]

    class_names = ['akiec', 'bcc', 'bkl', 'df', 'nv', 'vasc', 'mel']
    disease_info = {
        'akiec': "Actinic Keratoses and Intraepithelial Carcinoma (pre-cancerous lesion)",
        'bcc': "Basal Cell Carcinoma (a common type of skin cancer)",
        'bkl': "Benign Keratosis (non-cancerous lesion)",
        'df': "Dermatofibroma (benign skin lesion)",
        'nv': "Melanocytic Nevus (a common mole)",
        'vasc': "Vascular Lesions (benign lesion of blood vessels)",
        'mel': "Melanoma (most dangerous type of skin cancer)"
    }

    return f"{class_names[predicted_class]}: {disease_info[class_names[predicted_class]]}"

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