Spaces:
Sleeping
Sleeping
File size: 1,523 Bytes
adb3499 2e8f08d 6d524ca 1e811a4 136473c 728557c 2e8f08d adb3499 567ef04 e59318c 2e8f08d e59318c 2e8f08d 8a99c3d 2e8f08d 7f130f8 2e8f08d ef64671 c9b524d 3d8a117 728557c 21af319 1e811a4 eb0073f 5f24793 3d8a117 94f1da6 eee988a 21af319 728557c |
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 |
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import cv2
import keras
import gradio as gr
SHAPE = (224, 224, 3)
disease_risk = keras.models.load_model('predictor_Disease_Risk.h5')
def cut_and_resize(image):
LOW_TOL = 20
img_bw = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
img_bw[img_bw<=LOW_TOL] = 0
y_nonzero, x_nonzero = np.nonzero(img_bw)
image = image[np.min(y_nonzero):np.max(y_nonzero), np.min(x_nonzero): np.max(x_nonzero), ]
return cv2.resize(image, SHAPE[:2], interpolation = cv2.INTER_LINEAR)
def simple_normalizer(X):
return X / 255.0
def predict (image_path):
image = simple_normalizer(cut_and_resize(cv2.imread(image_path)))
result = disease_risk.predict(np.array([image]))[0][0]
return {'Enferma': float(result), 'Sana': 1 - float(result)}
title = 'RetinAI (versi贸n alfa)'
description = 'Modelo de deep learning que permite clasificar im谩genes de la retina en patol贸gicas y no patol贸gicas. Primera fase de un proyecto que pretende realizar screening de las principales enfermedades de la retina que producen ceguera. Las im谩genes deben tener fondo negro.'
article = 'Demo del proyecto para Saturdays.\nAutores del modelo: [...] '
interface = gr.Interface(
predict,
inputs = [gr.outputs.Image()],
outputs= [gr.outputs.Label(num_top_classes=2, label='Retina')],
title = title, description = description, article = article,
theme = 'peach',
examples = ['82.png', '15.png', '61.png', '37.png', '631.png', '23.png', '8.png']
)
interface.launch() |