File size: 729 Bytes
a81bafc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import tensorflow as tf
import numpy as np
import gradio as gr
from PIL import Image

# load model
model = tf.keras.models.load_model("model_resnet.keras")

CLASS_NAMES = ['MEL','NV','BCC','AK','BKL','DF','VASC','SCC']

def predict(image):
    img = image.resize((224, 224))
    img = np.array(img).astype("float32") / 255.0
    img = np.expand_dims(img, axis=0)

    pred = model.predict(img)
    idx = int(np.argmax(pred))
    conf = float(np.max(pred))

    return {
        "class": CLASS_NAMES[idx],
        "confidence": conf
    }

iface = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="pil"),
    outputs="json",
    title="ISIC 2019 Skin Cancer Classifier API"
)

iface.launch()