| import gradio as gr |
| import numpy as np |
| from PIL import Image |
| import tensorflow as tf |
| from tensorflow.keras.applications.mobilenet_v2 import preprocess_input |
|
|
| |
| model = tf.keras.models.load_model("modelo.h5") |
|
|
| |
| clases = ["Nevo", "Queratosis", "Carcinoma", "Melanoma", "Dermatitis"] |
|
|
| |
| def predict(image): |
| image = image.resize((224, 224)) |
| img = np.array(image) |
| |
| |
| img = preprocess_input(img) |
| img = np.expand_dims(img, axis=0) |
|
|
| pred = model.predict(img) |
| idx = np.argmax(pred) |
| confianza = float(np.max(pred)) |
|
|
| return { |
| clases[i]: float(pred[0][i]) for i in range(len(clases)) |
| } |
|
|
| |
| interface = gr.Interface( |
| fn=predict, |
| inputs=gr.Image(type="pil"), |
| outputs=gr.Label(num_top_classes=3), |
| title="馃 Derm-IA", |
| description="Asistente de diagn贸stico dermatol贸gico basado en IA" |
| ) |
|
|
| interface.launch() |