Araeynn commited on
Commit
9d524b4
·
verified ·
1 Parent(s): 5a69d7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -4,21 +4,23 @@ import tensorflow as tf
4
 
5
  model = from_pretrained_keras("araeynn/validation_model")
6
 
 
7
  def image_classifier(inp):
8
  class_names = ["0", "1"]
9
  inp.save("why.png")
10
  sunflower_path = "why.png"
11
- img = tf.keras.utils.load_img(
12
- sunflower_path, target_size=(256, 256)
13
- )
14
  img_array = tf.keras.utils.img_to_array(img)
15
- img_array = tf.expand_dims(img_array, 0) # Create a batch
16
 
17
  predictions = model.predict(img_array)
18
  score = tf.nn.softmax(predictions)
19
  r = {}
 
20
  for class_name in class_names:
21
- r[class_name] = score[0][class_names.index(class_name)]
22
  return r
 
 
23
  demo = gr.Interface(fn=image_classifier, inputs=gr.Image(type="pil"), outputs="label")
24
- demo.launch(debug=True)
 
4
 
5
  model = from_pretrained_keras("araeynn/validation_model")
6
 
7
+
8
  def image_classifier(inp):
9
  class_names = ["0", "1"]
10
  inp.save("why.png")
11
  sunflower_path = "why.png"
12
+ img = tf.keras.utils.load_img(sunflower_path, target_size=(256, 256))
 
 
13
  img_array = tf.keras.utils.img_to_array(img)
14
+ img_array = tf.expand_dims(img_array, 0) # Create a batch
15
 
16
  predictions = model.predict(img_array)
17
  score = tf.nn.softmax(predictions)
18
  r = {}
19
+ print(score)
20
  for class_name in class_names:
21
+ r[class_name] = score[0][class_names.index(class_name)]
22
  return r
23
+
24
+
25
  demo = gr.Interface(fn=image_classifier, inputs=gr.Image(type="pil"), outputs="label")
26
+ demo.launch(debug=True)