jsolow commited on
Commit
ea97a17
1 Parent(s): 19d9547

Use tf load_img

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  from huggingface_hub import from_pretrained_keras
3
- from tensorflow.keras.preprocessing.image import array_to_img, img_to_array
4
 
5
  from labels import CLASS_LABELS
6
 
@@ -8,11 +8,11 @@ from labels import CLASS_LABELS
8
  model = from_pretrained_keras("jsolow/grubguesser")
9
 
10
 
11
- def _preprocess(imgage_input):
12
- img = array_to_img(imgage_input, scale=False)
13
- img = img.resize((224, 224))
14
- img = img_to_array(img)
15
- return img / 255.0
16
 
17
 
18
  def predict(image):
 
1
  import gradio as gr
2
  from huggingface_hub import from_pretrained_keras
3
+ import tensorflow as tf
4
 
5
  from labels import CLASS_LABELS
6
 
 
8
  model = from_pretrained_keras("jsolow/grubguesser")
9
 
10
 
11
+ def _preprocess(image_path: str):
12
+ image = tf.keras.utils.load_img(image_path, target_size=(224, 224))
13
+ input_arr = tf.keras.utils.img_to_array(image)
14
+ input_arr = np.array([input_arr]) # Convert single image to a batch.
15
+ return input_arr
16
 
17
 
18
  def predict(image):