DHEIVER commited on
Commit
7806a41
·
1 Parent(s): fef3f6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -10,11 +10,9 @@ import tensorflow as tf
10
  from tensorflow.keras import backend as K
11
  from tensorflow.keras.models import load_model
12
  from tensorflow.keras.applications.imagenet_utils import preprocess_input
13
- from tensorflow.keras.applications.imagenet_utils import preprocess_input
14
 
15
  from sklearn.metrics import f1_score
16
 
17
-
18
  import gradio as gr
19
 
20
 
@@ -23,13 +21,13 @@ sns.set_style('darkgrid')
23
  if not sys.warnoptions:
24
  import warnings
25
  warnings.simplefilter("ignore")
26
- pd.set_option('display.max_columns', None) # or 1000
27
- pd.set_option('display.max_rows', None) # or 1000
28
- pd.set_option('display.max_colwidth', None) # or 199
29
  print('Modules loaded')
30
 
31
 
32
- def F1_score(y_true, y_pred): # taken from old keras source code
33
  true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
34
  possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
35
  predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
@@ -43,7 +41,7 @@ model = load_model(r"Model\Model.h5",
43
  custom_objects={"F1_score": f1_score})
44
 
45
 
46
- def recog_model(img_path):
47
  img = cv2.imread(img_path)
48
  img = cv2.resize(img, (250, 224))
49
  x = np.expand_dims(img, axis=0)
@@ -51,14 +49,12 @@ def recog_model(img_path):
51
 
52
  prediction = model.predict(x)
53
 
54
- # convert the prediction to a class label
55
  classes = ['Tumor', 'Cyst', 'Normal', 'Stone']
56
  predicted_class = classes[np.argmax(prediction[0])]
57
  confidence = str(100 * (np.max(prediction[0])))
58
- return (str(predicted_class+" detected with a confidence of "+confidence+"%"))
59
-
60
 
61
- demo = gr.Interface(fn=recog_model, inputs=gr.Image(image_mode="L", type="filepath", label="Input Image"),
62
- outputs=gr.Label(label="Model Prediction"), allow_flagging="never", examples=[r"demo\Cyst.jpg", r"demo\Normal.jpg", r"demo\Stone.jpg", r"demo\Tumor.jpg"])
63
 
64
- demo.launch()
 
 
 
10
  from tensorflow.keras import backend as K
11
  from tensorflow.keras.models import load_model
12
  from tensorflow.keras.applications.imagenet_utils import preprocess_input
 
13
 
14
  from sklearn.metrics import f1_score
15
 
 
16
  import gradio as gr
17
 
18
 
 
21
  if not sys.warnoptions:
22
  import warnings
23
  warnings.simplefilter("ignore")
24
+ pd.set_option('display.max_columns', None)
25
+ pd.set_option('display.max_rows', None)
26
+ pd.set_option('display.max_colwidth', None)
27
  print('Modules loaded')
28
 
29
 
30
+ def F1_score(y_true, y_pred):
31
  true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
32
  possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
33
  predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
 
41
  custom_objects={"F1_score": f1_score})
42
 
43
 
44
+ def image_recognition(img_path):
45
  img = cv2.imread(img_path)
46
  img = cv2.resize(img, (250, 224))
47
  x = np.expand_dims(img, axis=0)
 
49
 
50
  prediction = model.predict(x)
51
 
 
52
  classes = ['Tumor', 'Cyst', 'Normal', 'Stone']
53
  predicted_class = classes[np.argmax(prediction[0])]
54
  confidence = str(100 * (np.max(prediction[0])))
55
+ return str(predicted_class + " detected with a confidence of " + confidence + "%")
 
56
 
 
 
57
 
58
+ app = gr.Interface(fn=image_recognition, inputs=gr.Image(image_mode="L", type="filepath", label="Input Image"),
59
+ outputs=gr.Label(label="Model Prediction"), allow_flagging="never", examples=[r"demo\Cyst.jpg", r"demo\Normal.jpg", r"demo\Stone.jpg", r"demo\Tumor.jpg"], title="Sistema de Reconhecimento de Imagens Médicas")
60
+ app.launch()