AI-RESEARCHER-2024 commited on
Commit
0d33bd0
·
verified ·
1 Parent(s): 4f91b89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -5,6 +5,7 @@ from tensorflow.keras.models import load_model
5
  from tensorflow.keras.utils import to_categorical
6
  from tensorflow.keras.datasets import mnist
7
  import cv2
 
8
 
9
  # I/O image dimensions for display
10
  DIMS = (100, 100)
@@ -19,8 +20,10 @@ mnist_examples = [[cv2.resize(x_test[i], DIMS)] for i in range(10)]
19
 
20
  # Function to preprocess the image
21
  def preprocess_image(image):
 
 
22
  image = cv2.resize(image, (28, 28)) # Resize to 28x28 for model input
23
- image = np.array(image) / 255.0
24
  image = image.reshape(1, 28, 28, 1)
25
  return image
26
 
 
5
  from tensorflow.keras.utils import to_categorical
6
  from tensorflow.keras.datasets import mnist
7
  import cv2
8
+ from PIL import Image
9
 
10
  # I/O image dimensions for display
11
  DIMS = (100, 100)
 
20
 
21
  # Function to preprocess the image
22
  def preprocess_image(image):
23
+ if isinstance(image, Image.Image):
24
+ image = np.array(image)
25
  image = cv2.resize(image, (28, 28)) # Resize to 28x28 for model input
26
+ image = image / 255.0
27
  image = image.reshape(1, 28, 28, 1)
28
  return image
29