Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -28,9 +28,17 @@ model = models.load_model('tf_model.h5')
|
|
28 |
def preprocess_image(image):
|
29 |
# Resize the image
|
30 |
image = cv2.resize(image, IMG_SIZE)
|
31 |
-
|
32 |
-
#
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
# Convert the image to float32 and normalize
|
36 |
image = image.astype('float32') / 255.0
|
@@ -40,8 +48,6 @@ def preprocess_image(image):
|
|
40 |
|
41 |
return image
|
42 |
|
43 |
-
|
44 |
-
|
45 |
def main():
|
46 |
st.title("Character Recognition")
|
47 |
st.write("Upload an image and the model will predict the character")
|
|
|
28 |
def preprocess_image(image):
|
29 |
# Resize the image
|
30 |
image = cv2.resize(image, IMG_SIZE)
|
31 |
+
|
32 |
+
# Check if the image is grayscale
|
33 |
+
if len(image.shape) == 2:
|
34 |
+
# Convert grayscale image to RGB
|
35 |
+
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
|
36 |
+
elif image.shape[2] == 4:
|
37 |
+
# Convert RGBA image to RGB
|
38 |
+
image = cv2.cvtColor(image, cv2.COLOR_RGBA2RGB)
|
39 |
+
elif image.shape[2] > 3:
|
40 |
+
# Extract only the first 3 channels (assuming RGB or BGR format)
|
41 |
+
image = image[:, :, :3]
|
42 |
|
43 |
# Convert the image to float32 and normalize
|
44 |
image = image.astype('float32') / 255.0
|
|
|
48 |
|
49 |
return image
|
50 |
|
|
|
|
|
51 |
def main():
|
52 |
st.title("Character Recognition")
|
53 |
st.write("Upload an image and the model will predict the character")
|