import gradio as gr import pandas as pd import numpy as np #import os #from tqdm import tqdm #import tensorflow as tf #from tensorflow import keras #from keras.utils import np_utils #from keras.preprocessing import image #from keras.preprocessing.image import ImageDataGenerator #import matplotlib.pyplot as plt from keras.preprocessing import image from keras.applications.vgg16 import VGG16, preprocess_input file = open("womanlife.json", 'r') model_json2 = file.read() file.close() loaded_model = model_from_json(model_json2) loaded_model.load_weights("womanlife.h5") #new_model = tf.keras.models.load_model('modelo_entrenado.h5') objects = ('There is a benign nodule', 'Normal Breast', 'There is a malignant nodule') y_pos = np.arange(len(objects)) def predict_image(pic): img = image.load_img(pic, target_size=(224, 224)) x = image.img_to_array(img) x = np.expand_dims(x, axis=0) x = preprocess_input(x) #img = image.load_img(pic, grayscale=True, target_size=(48, 48)) #x = image.img_to_array(img) #x = np.expand_dims(x, axis = 0) #x /= 255 custom = loaded_model.predict(x) m=0.000000000000000000001 a=custom[0] for i in range(0,len(a)): if a[i]>m: m=a[i] ind=i return ('Result of the analysis:',objects[ind]) iface = gr.Interface( predict_image, [ gr.inputs.Image(source="upload",type="filepath", label="Imagen") ], "text", interpretation="default", title = 'WomanLife: Deep Learning for the detection of breast cancer', description = 'Breast cancer is the most common type of cancer in women and is also one of the main causes of death according to the WHO (WHO, 2020). Early detection is the single most important factor in lowering cancer treatment costs and mortality. https://saturdays.ai/2021/12/31/womanlife-deep-learning-for-the-detection-and-classification-of-breast-cancer-2/', examples=[["A.png"], ["B.png"], ["C.png"], ["D.png"], ["E.png"], ["F.png"]], theme = 'pink' ) iface.launch()