sains-data-model / predict.py
suyagi's picture
Upload folder using huggingface_hub
a81bafc verified
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()