sowbaranika13 commited on
Commit
30b097d
1 Parent(s): 027b915

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -1
app.py CHANGED
@@ -3,6 +3,7 @@ import tensorflow as tf
3
  from tensorflow.keras.models import load_model
4
  from tensorflow.keras.preprocessing.image import img_to_array,load_img
5
  import numpy as np
 
6
  import os
7
 
8
  # Load your model and tokenizer
@@ -20,7 +21,8 @@ model_path = r"inceptionv3_class.h5"
20
  hierarchical_models['class'] = load_model(model_path)
21
 
22
  def load_and_preprocess_image(image, target_size=(224, 224)):
23
- image = load_img(image, target_size=(224, 224))
 
24
  img_array = img_to_array(image)
25
  img_array = np.expand_dims(img_array, axis=0)
26
  img_array = tf.keras.applications.mobilenet_v2.preprocess_input(img_array)
 
3
  from tensorflow.keras.models import load_model
4
  from tensorflow.keras.preprocessing.image import img_to_array,load_img
5
  import numpy as np
6
+ from PIL import Image
7
  import os
8
 
9
  # Load your model and tokenizer
 
21
  hierarchical_models['class'] = load_model(model_path)
22
 
23
  def load_and_preprocess_image(image, target_size=(224, 224)):
24
+ if isinstance(image, Image.Image):
25
+ image = image.resize(target_size)
26
  img_array = img_to_array(image)
27
  img_array = np.expand_dims(img_array, axis=0)
28
  img_array = tf.keras.applications.mobilenet_v2.preprocess_input(img_array)