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()