hb-setosys commited on
Commit
dc05c78
·
verified ·
1 Parent(s): 2fb41bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -13
app.py CHANGED
@@ -1,29 +1,18 @@
1
  import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
4
- from PIL import Image
5
 
6
  # Load the trained model
7
  model = tf.keras.models.load_model("denis_mnist_cnn_model.h5")
8
 
9
  # Preprocessing function for images
10
  def preprocess_image(image):
11
- # Convert PIL image to a tensor
12
- image = tf.convert_to_tensor(image)
13
-
14
  # Resize the image to 28x28 as expected by the model
15
  image = tf.image.resize(image, (28, 28)) # Resize to 28x28
16
-
17
- # If the image is RGB, convert it to grayscale
18
- if image.shape[-1] == 3:
19
- image = tf.image.rgb_to_grayscale(image) # Convert RGB to grayscale
20
 
21
- # Normalize pixel values to [0, 1]
22
- image = image / 255.0
23
 
24
- # Convert grayscale to RGB (3 channels)
25
- image = tf.image.grayscale_to_rgb(image) # Convert grayscale to RGB (3 channels)
26
-
27
  # Add batch dimension (model expects batch of images)
28
  image = tf.expand_dims(image, axis=0)
29
 
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
 
4
 
5
  # Load the trained model
6
  model = tf.keras.models.load_model("denis_mnist_cnn_model.h5")
7
 
8
  # Preprocessing function for images
9
  def preprocess_image(image):
 
 
 
10
  # Resize the image to 28x28 as expected by the model
11
  image = tf.image.resize(image, (28, 28)) # Resize to 28x28
 
 
 
 
12
 
13
+ # Convert image to float32 and normalize pixel values to [0, 1]
14
+ image = tf.cast(image, tf.float32) / 255.0
15
 
 
 
 
16
  # Add batch dimension (model expects batch of images)
17
  image = tf.expand_dims(image, axis=0)
18