skincancer / inference.py
DayanaRR00456's picture
Upload 2 files
30b8603 verified
import tensorflow as tf
from PIL import Image
import numpy as np
# Cargar modelo H5
model = tf.keras.models.load_model("modelo_skin_cancer final.h5")
# Preprocesar imagen
def preprocess(image):
image = image.convert("RGB")
image = image.resize((300, 300))
image_array = np.array(image) / 255.0
image_array = np.expand_dims(image_array, axis=0)
return image_array
# Función de inferencia para Hugging Face
def predict(image):
image = preprocess(image)
prediction = model.predict(image)[0][0]
label = "Maligno" if prediction > 0.5 else "Benigno"
return { "label": label, "confidence": float(prediction) }