Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,7 @@ class CustomLSTM(LSTM):
|
|
14 |
# Caching the model loading function to optimize performance
|
15 |
@st.cache_resource
|
16 |
def load_captcha_model():
|
17 |
-
model_path = "captcha_ocr_model.h5" #
|
18 |
return tf.keras.models.load_model(model_path, custom_objects={'CustomLSTM': CustomLSTM})
|
19 |
|
20 |
# Load the model
|
@@ -24,10 +24,10 @@ model = load_captcha_model()
|
|
24 |
def prepare_captcha_image(img):
|
25 |
try:
|
26 |
# Resize image to the input shape required by the CAPTCHA model
|
27 |
-
img = img.resize((200, 50)) #
|
28 |
-
img_array = np.array(img.convert('L')) #
|
29 |
-
img_array = img_array / 255.0 #
|
30 |
-
img_array = np.expand_dims(img_array, axis=0) #
|
31 |
|
32 |
# Predict the CAPTCHA characters
|
33 |
predictions = model.predict(img_array)
|
|
|
14 |
# Caching the model loading function to optimize performance
|
15 |
@st.cache_resource
|
16 |
def load_captcha_model():
|
17 |
+
model_path = "captcha_ocr_model.h5" # Update with the actual CAPTCHA model path
|
18 |
return tf.keras.models.load_model(model_path, custom_objects={'CustomLSTM': CustomLSTM})
|
19 |
|
20 |
# Load the model
|
|
|
24 |
def prepare_captcha_image(img):
|
25 |
try:
|
26 |
# Resize image to the input shape required by the CAPTCHA model
|
27 |
+
img = img.resize((200, 50)) # Adjust size according to the trained model
|
28 |
+
img_array = np.array(img.convert('L')) # Convert to grayscale if necessary
|
29 |
+
img_array = img_array / 255.0 # Normalize image
|
30 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
31 |
|
32 |
# Predict the CAPTCHA characters
|
33 |
predictions = model.predict(img_array)
|