DarkyMan commited on
Commit
ca69b8b
β€’
1 Parent(s): 8f12800

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -20,18 +20,16 @@ prediction_model = keras.models.Model(
20
  with open("vocab.txt", "r") as f:
21
  vocab = f.read().splitlines()
22
 
23
- # Mapping integers back to original characters
24
  num_to_char = layers.StringLookup(
25
  vocabulary=vocab, mask_token=None, invert=True
26
  )
27
 
28
  def decode_batch_predictions(pred):
29
  input_len = np.ones(pred.shape[0]) * pred.shape[1]
30
- # Use greedy search. For complex tasks, you can use beam search
31
  results = keras.backend.ctc_decode(pred, input_length=input_len, greedy=True)[0][0][
32
  :, :max_length
33
  ]
34
- # Iterate over the results and get back the text
35
  output_text = []
36
  for res in results:
37
  res = tf.strings.reduce_join(num_to_char(res)).numpy().decode("utf-8")
@@ -39,16 +37,10 @@ def decode_batch_predictions(pred):
39
  return output_text
40
 
41
  def classify_image(img_path):
42
- # 1. Read image
43
  img = tf.io.read_file(img_path)
44
- # 2. Decode and convert to grayscale
45
  img = tf.io.decode_png(img, channels=1)
46
- # 3. Convert to float32 in [0, 1] range
47
  img = tf.image.convert_image_dtype(img, tf.float32)
48
- # 4. Resize to the desired size
49
  img = tf.image.resize(img, [img_height, img_width])
50
- # 5. Transpose the image because we want the time
51
- # dimension to correspond to the width of the image.
52
  img = tf.transpose(img, perm=[1, 0, 2])
53
  img = tf.expand_dims(img, axis=0)
54
  preds = prediction_model.predict(img)
@@ -59,9 +51,9 @@ image = gr.inputs.Image(type='filepath')
59
  text = gr.outputs.Textbox()
60
 
61
  iface = gr.Interface(classify_image,image,text,
62
- title="OCR for CAPTCHA",
63
- description = "Keras Implementation of OCR model for reading captcha πŸ€–πŸ¦ΉπŸ»",
64
- article = "Author: <a href=\"https://huggingface.co/anuragshas\">Anurag Singh</a>. Based on the keras example from <a href=\"https://keras.io/examples/vision/captcha_ocr/\">A_K_Nain</a>",
65
  examples = ["dd764.png","3p4nn.png"]
66
  )
67
 
 
20
  with open("vocab.txt", "r") as f:
21
  vocab = f.read().splitlines()
22
 
 
23
  num_to_char = layers.StringLookup(
24
  vocabulary=vocab, mask_token=None, invert=True
25
  )
26
 
27
  def decode_batch_predictions(pred):
28
  input_len = np.ones(pred.shape[0]) * pred.shape[1]
 
29
  results = keras.backend.ctc_decode(pred, input_length=input_len, greedy=True)[0][0][
30
  :, :max_length
31
  ]
32
+
33
  output_text = []
34
  for res in results:
35
  res = tf.strings.reduce_join(num_to_char(res)).numpy().decode("utf-8")
 
37
  return output_text
38
 
39
  def classify_image(img_path):
 
40
  img = tf.io.read_file(img_path)
 
41
  img = tf.io.decode_png(img, channels=1)
 
42
  img = tf.image.convert_image_dtype(img, tf.float32)
 
43
  img = tf.image.resize(img, [img_height, img_width])
 
 
44
  img = tf.transpose(img, perm=[1, 0, 2])
45
  img = tf.expand_dims(img, axis=0)
46
  preds = prediction_model.predict(img)
 
51
  text = gr.outputs.Textbox()
52
 
53
  iface = gr.Interface(classify_image,image,text,
54
+ title="un-captcha",
55
+ description = "Recognizes captcha text (pictures)|РаспознаСт тСкст ΠΊΠ°ΠΏΡ‡ΠΈ (ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ)",
56
+ article = "Π‘ΡŽΠ΄Ρ‹: https://huggingface.co/DarkyMan/",
57
  examples = ["dd764.png","3p4nn.png"]
58
  )
59