File size: 2,094 Bytes
ab04ca6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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()