Spaces:
Sleeping
Sleeping
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() |