fbadine commited on
Commit
c7789fd
1 Parent(s): 32358e5

Update app.py

Browse files

Added debugging info

Files changed (1) hide show
  1. app.py +27 -5
app.py CHANGED
@@ -12,9 +12,21 @@ model = from_pretrained_keras(
12
  pretrained_model_name_or_path="fbadine/image-spam-detection"
13
  )
14
 
 
 
 
 
 
 
 
 
 
15
  # This is the predict function that takes as input an array-like-image and produces
16
  # the probabilities that this image is either spam or ham
17
  def predict(image):
 
 
 
18
  # Resize image
19
  resized_image = keras.layers.Resizing(
20
  IMAGE_SIZE[0],
@@ -24,16 +36,25 @@ def predict(image):
24
  )(image)
25
  resized_image = tf.expand_dims(resized_image, axis=0)
26
 
 
 
 
 
27
  # Predict
28
  pred = model.predict(resized_image)
29
  prob = float(pred[0][0])
30
 
 
 
 
 
31
  scoring_output = {
32
  "Spam": prob,
33
  "Ham": 1 - prob
34
  }
35
 
36
- return scoring_output
 
37
 
38
  # Clear Input and outpout
39
  def clear_inputs_and_outputs():
@@ -67,9 +88,9 @@ if __name__ == "__main__":
67
  with gr.Column():
68
  # Output
69
  lbl_output = gr.Label(label="Prediction")
70
- #plt_output = gr.Plot(
71
- # label="Prediction", show_label=False
72
- #)
73
 
74
  clr_btn.click(
75
  fn=clear_inputs_and_outputs,
@@ -79,7 +100,8 @@ if __name__ == "__main__":
79
  prd_btn.click(
80
  fn=predict,
81
  inputs=[image_input],
82
- outputs=[lbl_output],
 
83
  )
84
 
85
  gr.Examples(
 
12
  pretrained_model_name_or_path="fbadine/image-spam-detection"
13
  )
14
 
15
+ ####### To be removed
16
+ def get_txt_output(arr):
17
+ txt = f"Image shape: {arr.shape}\n"
18
+ txt += f"Min: {np.min(arr)}, Max: {np.max(arr)}\n"
19
+ txt += f"Image hash: {hash(tuple(arr.reshape(-1)))}\n\n"
20
+
21
+ return txt
22
+ ####### End
23
+
24
  # This is the predict function that takes as input an array-like-image and produces
25
  # the probabilities that this image is either spam or ham
26
  def predict(image):
27
+ ####### To be removed
28
+ txt_output = get_txt_output(image)
29
+ ####### End
30
  # Resize image
31
  resized_image = keras.layers.Resizing(
32
  IMAGE_SIZE[0],
 
36
  )(image)
37
  resized_image = tf.expand_dims(resized_image, axis=0)
38
 
39
+ ####### To be removed
40
+ txt_output += get_txt_output(resized_image.numpy())
41
+ ####### End
42
+
43
  # Predict
44
  pred = model.predict(resized_image)
45
  prob = float(pred[0][0])
46
 
47
+ ####### To be removed
48
+ txt_output += f"Probability: {prob}"
49
+ ####### End
50
+
51
  scoring_output = {
52
  "Spam": prob,
53
  "Ham": 1 - prob
54
  }
55
 
56
+ #return scoring_output
57
+ return [scoring_output, txt_output]
58
 
59
  # Clear Input and outpout
60
  def clear_inputs_and_outputs():
 
88
  with gr.Column():
89
  # Output
90
  lbl_output = gr.Label(label="Prediction")
91
+ ####### To be removed
92
+ txt_output = gr.TextArea(label="info_out")
93
+ ####### End
94
 
95
  clr_btn.click(
96
  fn=clear_inputs_and_outputs,
 
100
  prd_btn.click(
101
  fn=predict,
102
  inputs=[image_input],
103
+ #outputs=[lbl_output],
104
+ outputs=[lbl_output, txt_output],
105
  )
106
 
107
  gr.Examples(