ChanhVo commited on
Commit
ed0eb68
1 Parent(s): d0a5ec3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import TrOCRProcessor, VisionEncoderDecoderModel
3
+
4
+ name = "chanelcolgate/trocr-base-printed_captcha_ocr"
5
+ model = VisionEncoderDecoderModel.from_pretrained(name)
6
+ processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-printed")
7
+
8
+
9
+ def process_image(image):
10
+ # prepare image
11
+ pixel_values = processor(image, return_tensors="pt").pixel_values
12
+
13
+ # generate (no beam search)
14
+ generated_ids = model.generate(pixel_values)
15
+
16
+ # decode
17
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
18
+ return generated_text
19
+
20
+
21
+ title = "Interactive demo: Captcha OCR"
22
+ description = "Demo tracuumasothue captcha"
23
+
24
+ interface = gr.Interface(fn=process_image,
25
+ inputs="image",
26
+ examples=[f"examples/captcha-{i}.png" for i in range(10)],
27
+ outputs="text",
28
+ title=title,
29
+ description=description).launch()