Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,18 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import tensorflow as tf
|
|
|
4 |
import numpy as np
|
5 |
import os
|
|
|
6 |
|
7 |
# Caching the model loading function to optimize performance
|
8 |
@st.cache_resource
|
9 |
def load_captcha_model():
|
10 |
model_path = "captcha_ocr_model.h5" # Update with the actual CAPTCHA model path
|
11 |
-
|
|
|
|
|
12 |
|
13 |
# Load the model
|
14 |
model = load_captcha_model()
|
@@ -26,7 +30,6 @@ def prepare_captcha_image(img):
|
|
26 |
predictions = model.predict(img_array)
|
27 |
|
28 |
# Decode predictions assuming the model outputs probabilities
|
29 |
-
# Modify this part based on your specific model's output
|
30 |
decoded_captcha = ''.join([chr(np.argmax(pred) + ord('A')) for pred in predictions])
|
31 |
|
32 |
return decoded_captcha, predictions
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import tensorflow as tf
|
4 |
+
from tensorflow.keras.models import load_model
|
5 |
import numpy as np
|
6 |
import os
|
7 |
+
from tensorflow.keras.layers import LSTM
|
8 |
|
9 |
# Caching the model loading function to optimize performance
|
10 |
@st.cache_resource
|
11 |
def load_captcha_model():
|
12 |
model_path = "captcha_ocr_model.h5" # Update with the actual CAPTCHA model path
|
13 |
+
|
14 |
+
# Load the model with custom objects
|
15 |
+
return tf.keras.models.load_model(model_path, custom_objects={'LSTM': LSTM})
|
16 |
|
17 |
# Load the model
|
18 |
model = load_captcha_model()
|
|
|
30 |
predictions = model.predict(img_array)
|
31 |
|
32 |
# Decode predictions assuming the model outputs probabilities
|
|
|
33 |
decoded_captcha = ''.join([chr(np.argmax(pred) + ord('A')) for pred in predictions])
|
34 |
|
35 |
return decoded_captcha, predictions
|