Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
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="
|
63 |
-
description = "
|
64 |
-
article = "
|
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 |
|