FreeXrayCovid / app.py
sebasfb99's picture
Update app.py
b1f94d4 verified
raw
history blame
1.09 kB
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):
# Preprocesar la imagen
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
# Realizar la predicci贸n
prediction = model.predict(img_array)
# Interpretar la predicci贸n
result = 'COVID19' if prediction[0][0] < 0.5 else 'NORMAL'
return result, "If you don't have an image, please download one from this link: https://drive.google.com/drive/folders/1Dr11dKuSlgtWaTzNLRixzB19y588iNib?usp=sharing"
# Crear la interfaz de Gradio
iface = gr.Interface(fn=predict_image,inputs=gr.Image(type="pil"), outputs=[gr.Textbox(label="Prediction"), gr.Textbox(label="Download Link")], live=True)
# Lanzar la interfaz
iface.launch()