KikoDM commited on
Commit
ab04ca6
1 Parent(s): 1812355

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+ #import os
5
+ #from tqdm import tqdm
6
+ #import tensorflow as tf
7
+ #from tensorflow import keras
8
+ #from keras.utils import np_utils
9
+ #from keras.preprocessing import image
10
+ #from keras.preprocessing.image import ImageDataGenerator
11
+ #import matplotlib.pyplot as plt
12
+
13
+ from keras.preprocessing import image
14
+ from keras.applications.vgg16 import VGG16, preprocess_input
15
+
16
+ file = open("womanlife.json", 'r')
17
+ model_json2 = file.read()
18
+ file.close()
19
+ loaded_model = model_from_json(model_json2)
20
+ loaded_model.load_weights("womanlife.h5")
21
+
22
+ #new_model = tf.keras.models.load_model('modelo_entrenado.h5')
23
+ objects = ('There is a benign nodule', 'Normal Breast', 'There is a malignant nodule')
24
+ y_pos = np.arange(len(objects))
25
+
26
+
27
+
28
+ def predict_image(pic):
29
+
30
+ img = image.load_img(pic, target_size=(224, 224))
31
+ x = image.img_to_array(img)
32
+ x = np.expand_dims(x, axis=0)
33
+ x = preprocess_input(x)
34
+
35
+ #img = image.load_img(pic, grayscale=True, target_size=(48, 48))
36
+ #x = image.img_to_array(img)
37
+
38
+ #x = np.expand_dims(x, axis = 0)
39
+
40
+ #x /= 255
41
+
42
+ custom = loaded_model.predict(x)
43
+
44
+ m=0.000000000000000000001
45
+ a=custom[0]
46
+ for i in range(0,len(a)):
47
+ if a[i]>m:
48
+ m=a[i]
49
+ ind=i
50
+
51
+ return ('Result of the analysis:',objects[ind])
52
+
53
+ iface = gr.Interface(
54
+ predict_image,
55
+ [
56
+
57
+ gr.inputs.Image(source="upload",type="filepath", label="Imagen")
58
+ ],
59
+
60
+ "text",
61
+
62
+
63
+ interpretation="default",
64
+ title = 'WomanLife: Deep Learning for the detection of breast cancer',
65
+ 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/',
66
+ examples=[["A.png"], ["B.png"], ["C.png"], ["D.png"], ["E.png"], ["F.png"]],
67
+ theme = 'pink'
68
+ )
69
+
70
+
71
+
72
+ iface.launch()