Reaumur commited on
Commit
6f1cee7
·
verified ·
1 Parent(s): dcca9ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
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" # Ganti dengan path model CAPTCHA yang sebenarnya
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)) # Sesuaikan ukuran sesuai model yang dilatih
28
- img_array = np.array(img.convert('L')) # Konversi ke grayscale jika perlu
29
- img_array = img_array / 255.0 # Normalisasi gambar
30
- img_array = np.expand_dims(img_array, axis=0) # Tambahkan dimensi batch
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)