chanelcolgate commited on
Commit
0ce48e6
1 Parent(s): 286a1e3

new file: app.py

Browse files
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"captcha-{i}.png" for i in range(10)],
27
+ outputs="text",
28
+ title=title,
29
+ description=description).launch()
examples/captcha-0.png ADDED
examples/captcha-1.png ADDED
examples/captcha-2.png ADDED
examples/captcha-3.png ADDED
examples/captcha-4.png ADDED
examples/captcha-5.png ADDED
examples/captcha-6.png ADDED
examples/captcha-7.png ADDED
examples/captcha-8.png ADDED
examples/captcha-9.png ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ transformers