File size: 2,296 Bytes
298ef45
 
 
80ee116
298ef45
 
 
 
 
 
3e57a9c
4ff4ace
8e74d0b
3e57a9c
 
 
 
 
 
 
 
 
 
 
 
4ff4ace
8e74d0b
3e57a9c
4ff4ace
298ef45
8e74d0b
3e57a9c
 
 
4ff4ace
3e57a9c
4ff4ace
 
6fe913c
4ff4ace
 
 
 
 
 
6fe913c
4ff4ace
 
 
 
6fe913c
 
 
 
 
4ff4ace
3e57a9c
298ef45
 
3e57a9c
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import img_to_array

# Cargar el modelo .keras
model = load_model('cnn_covid.keras')

# Funci贸n para hacer la predicci贸n
def predict_image(image):
    if image is None:
        return "Por favor suba una imagen / Please upload an image"
    
    try:
        img = image.resize((200, 200))  # Redimensionar a 200x200
        img_array = img_to_array(img)
        img_array = np.expand_dims(img_array, axis=0)  # A帽adir dimensi贸n para el batch
        
        prediction = model.predict(img_array)
        
        if prediction[0][0] < 0.5:
            result = "COVID-19 Detectado (COVID-19 Detected)"
        else:
            result = "No tiene COVID-19 (No COVID-19 detected)"
        
        return result
    
    except Exception as e:
        return f"Error en el procesamiento: {str(e)}"

# Crear la interfaz de Gradio
iface = gr.Interface(
    fn=predict_image,
    inputs=gr.Image(type="pil"),
    outputs=gr.Textbox(label="Resultado de la predicci贸n", lines=2),
    title="COVID-19 X-Ray Classifier",
    description="""
    [Espa帽ol]
    Precisi贸n del modelo: 98.9% (11 errores por cada 1000 im谩genes analizadas)
    Si desea probar el modelo, puede descargar im谩genes desde este enlace:
    https://drive.google.com/drive/folders/1Dr11dKuSlgtWaTzNLRixzB19y588iNib?usp=drive_link

    Algunas de estas im谩genes fueron utilizadas para entrenar el modelo, mientras que otras fueron reservadas exclusivamente para validaci贸n (el modelo nunca tuvo contacto con ellas durante el entrenamiento). Esto permite una evaluaci贸n m谩s precisa del rendimiento real del modelo.

    [English]
    Model Accuracy: 98.9% (11 errors per 1000 images analyzed)
    If you want to test the model, you can download images from this link:
    https://drive.google.com/drive/folders/1Dr11dKuSlgtWaTzNLRixzB19y588iNib?usp=drive_link

    Some of these images were used to train the model, while others were exclusively reserved for validation (the model never interacted with them during training). This allows for a more accurate evaluation of the model's real performance.

    


    
    """
)

# Lanzar la interfaz
if __name__ == "__main__":
    iface.launch()