daviddwlee84 commited on
Commit
645bae9
·
1 Parent(s): a4f0c21

Solve dependency issue and Add demo result

Browse files
Files changed (6) hide show
  1. 4326.png +0 -0
  2. app.py +12 -14
  3. demo_3p4nn.png +0 -0
  4. demo_4326.png +0 -0
  5. demo_dd764.png +0 -0
  6. requirements.txt +8 -1
4326.png ADDED
app.py CHANGED
@@ -21,9 +21,8 @@ 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]
@@ -38,6 +37,7 @@ def decode_batch_predictions(pred):
38
  output_text.append(res)
39
  return output_text
40
 
 
41
  def classify_image(img_path):
42
  # 1. Read image
43
  img = tf.io.read_file(img_path)
@@ -54,17 +54,15 @@ def classify_image(img_path):
54
  preds = prediction_model.predict(img)
55
  pred_text = decode_batch_predictions(preds)
56
  return pred_text[0]
57
-
58
- 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
 
68
 
69
- iface.launch()
 
 
 
 
 
 
70
 
 
 
 
21
  vocab = f.read().splitlines()
22
 
23
  # Mapping integers back to original characters
24
+ num_to_char = layers.StringLookup(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]
 
37
  output_text.append(res)
38
  return output_text
39
 
40
+
41
  def classify_image(img_path):
42
  # 1. Read image
43
  img = tf.io.read_file(img_path)
 
54
  preds = prediction_model.predict(img)
55
  pred_text = decode_batch_predictions(preds)
56
  return pred_text[0]
 
 
 
 
 
 
 
 
 
 
57
 
58
 
59
+ demo = gr.Interface(
60
+ fn=classify_image,
61
+ inputs=gr.Image(type="filepath"),
62
+ outputs=gr.Textbox(),
63
+ title="CAPTCHA OCR",
64
+ description="Upload a CAPTCHA image to recognize the text",
65
+ )
66
 
67
+ if __name__ == "__main__":
68
+ demo.launch(share=True)
demo_3p4nn.png ADDED
demo_4326.png ADDED
demo_dd764.png ADDED
requirements.txt CHANGED
@@ -1 +1,8 @@
1
- tensorflow>2.6
 
 
 
 
 
 
 
 
1
+ tensorflow>=2.6,<2.15
2
+ keras<3.0.0
3
+ # Local requirements
4
+ huggingface_hub
5
+ numpy<2
6
+ # IMPORTANT: You are using gradio version 3.50.2, however version 4.44.1 is available, please upgrade.
7
+ gradio>=3.50.0,<4.0.0
8
+ httpx[socks]