Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,21 +3,52 @@ import numpy as np
|
|
| 3 |
import tensorflow as tf
|
| 4 |
from tensorflow.keras.models import load_model
|
| 5 |
from tensorflow.keras.preprocessing import image
|
|
|
|
|
|
|
| 6 |
MODEL_ISATRON_JEY = 'modelo_isatron_jeysshonl.h5'
|
| 7 |
cnn_model = load_model(MODEL_ISATRON_JEY)
|
|
|
|
| 8 |
def make_prediction(test_image):
|
|
|
|
|
|
|
| 9 |
test_image = image.load_img(test_image, target_size=(224, 224))
|
| 10 |
-
test_image = image.img_to_array(test_image) / 255.
|
| 11 |
test_image = np.expand_dims(test_image, axis=0)
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
examples = [
|
| 22 |
['1normal.jpeg'],
|
| 23 |
['image1_pneumonia_virus.jpeg'],
|
|
@@ -27,14 +58,29 @@ examples = [
|
|
| 27 |
['image3_normal.jpeg'],
|
| 28 |
['image4_normal.jpeg'],
|
| 29 |
]
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
interface = gr.Interface(
|
| 32 |
fn=make_prediction,
|
| 33 |
inputs=image_input,
|
| 34 |
-
outputs=
|
| 35 |
-
title="
|
| 36 |
description=description,
|
| 37 |
article=article,
|
| 38 |
-
examples=examples
|
|
|
|
|
|
|
| 39 |
)
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import tensorflow as tf
|
| 4 |
from tensorflow.keras.models import load_model
|
| 5 |
from tensorflow.keras.preprocessing import image
|
| 6 |
+
|
| 7 |
+
# Cargar modelo
|
| 8 |
MODEL_ISATRON_JEY = 'modelo_isatron_jeysshonl.h5'
|
| 9 |
cnn_model = load_model(MODEL_ISATRON_JEY)
|
| 10 |
+
|
| 11 |
def make_prediction(test_image):
|
| 12 |
+
"""Realiza la predicción de neumonía en la imagen de rayos X"""
|
| 13 |
+
# Cargar y preprocesar imagen
|
| 14 |
test_image = image.load_img(test_image, target_size=(224, 224))
|
| 15 |
+
test_image = image.img_to_array(test_image) / 255.0
|
| 16 |
test_image = np.expand_dims(test_image, axis=0)
|
| 17 |
+
|
| 18 |
+
# Realizar predicción
|
| 19 |
+
result = cnn_model.predict(test_image, verbose=0)
|
| 20 |
+
|
| 21 |
+
# Retornar resultados
|
| 22 |
+
return {
|
| 23 |
+
"Normal": float(result[0][0]),
|
| 24 |
+
"Neumonía": float(result[0][1])
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
# Configuración de la interfaz
|
| 28 |
+
image_input = gr.Image(type="filepath", label="Subir imagen de rayos X")
|
| 29 |
+
|
| 30 |
+
description = """
|
| 31 |
+
<div style='text-align: justify;'>
|
| 32 |
+
El modelo <strong>IsaTron</strong> es una Red Neuronal Convolucional (CNN) diseñada como un método de apoyo médico
|
| 33 |
+
para el diagnóstico en imágenes radiológicas de neumonía pediátrica. IsaTron analiza radiografías torácicas y
|
| 34 |
+
proporciona un porcentaje de probabilidad para cada clase (Normal o Neumonía).
|
| 35 |
+
</div>
|
| 36 |
+
<br>
|
| 37 |
+
<div style='text-align: justify;'>
|
| 38 |
+
<strong>⚠️ Advertencia:</strong> Esta herramienta está diseñada exclusivamente como apoyo al diagnóstico y NO reemplaza
|
| 39 |
+
la evaluación médica profesional. Los resultados deben ser interpretados por personal de salud calificado.
|
| 40 |
+
</div>
|
| 41 |
+
<br>
|
| 42 |
+
<div style='text-align: justify;'>
|
| 43 |
+
En la parte inferior encontrará imágenes de ejemplo que pueden ser usadas para probar el funcionamiento del modelo.
|
| 44 |
+
</div>
|
| 45 |
+
<br>
|
| 46 |
+
<div style='text-align: center;'>
|
| 47 |
+
📚 Más información: <a href="https://repositorio.unbosque.edu.co/handle/20.500.12495/9514" target="_blank">
|
| 48 |
+
Repositorio Universidad El Bosque</a>
|
| 49 |
+
</div>
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
examples = [
|
| 53 |
['1normal.jpeg'],
|
| 54 |
['image1_pneumonia_virus.jpeg'],
|
|
|
|
| 58 |
['image3_normal.jpeg'],
|
| 59 |
['image4_normal.jpeg'],
|
| 60 |
]
|
| 61 |
+
|
| 62 |
+
article = """
|
| 63 |
+
<hr>
|
| 64 |
+
<div style='text-align: center;'>
|
| 65 |
+
<p><strong>IsaTron - Sistema de Apoyo al Diagnóstico de Neumonía</strong></p>
|
| 66 |
+
<p>Desarrollado por <strong>Jeysshon Bustos</strong></p>
|
| 67 |
+
<p>Universidad El Bosque © 2022-2024</p>
|
| 68 |
+
</div>
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
# Crear interfaz
|
| 72 |
interface = gr.Interface(
|
| 73 |
fn=make_prediction,
|
| 74 |
inputs=image_input,
|
| 75 |
+
outputs=gr.Label(label="Predicción", num_top_classes=2),
|
| 76 |
+
title="🏥 IsaTron: Detección de Neumonía con IA",
|
| 77 |
description=description,
|
| 78 |
article=article,
|
| 79 |
+
examples=examples,
|
| 80 |
+
theme=gr.themes.Soft(),
|
| 81 |
+
allow_flagging="never"
|
| 82 |
)
|
| 83 |
+
|
| 84 |
+
# Lanzar aplicación
|
| 85 |
+
if __name__ == "__main__":
|
| 86 |
+
interface.launch()
|