Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ from transformers import VisionEncoderDecoderModel, TrOCRProcessor
|
|
| 3 |
import torch
|
| 4 |
|
| 5 |
def recognize_captcha(input, mdl):
|
| 6 |
-
input =
|
| 7 |
|
| 8 |
# Load model and processor
|
| 9 |
processor = TrOCRProcessor.from_pretrained(mdl)
|
|
@@ -15,16 +15,18 @@ def recognize_captcha(input, mdl):
|
|
| 15 |
# Generate text
|
| 16 |
generated_ids = model.generate(pixel_values)
|
| 17 |
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
|
|
|
| 18 |
return generated_text
|
| 19 |
|
| 20 |
iface = gr.Interface(
|
| 21 |
-
recognize_captcha
|
|
|
|
| 22 |
gr.Image,
|
| 23 |
gr.Dropdown(
|
| 24 |
['anuashok/ocr-captcha-v3','anuashok/ocr-captcha-v2','anuashok/ocr-captcha-v1'], label='Model to use'
|
| 25 |
)
|
| 26 |
],
|
| 27 |
-
'text',
|
| 28 |
title = "character sequence recognition from scene-image (captcha)",
|
| 29 |
description = "Using some TrOCR models found on the HF Hub. Will you have to train your own?",
|
| 30 |
examples = ['','']
|
|
|
|
| 3 |
import torch
|
| 4 |
|
| 5 |
def recognize_captcha(input, mdl):
|
| 6 |
+
input = input.convert('RGB')
|
| 7 |
|
| 8 |
# Load model and processor
|
| 9 |
processor = TrOCRProcessor.from_pretrained(mdl)
|
|
|
|
| 15 |
# Generate text
|
| 16 |
generated_ids = model.generate(pixel_values)
|
| 17 |
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 18 |
+
|
| 19 |
return generated_text
|
| 20 |
|
| 21 |
iface = gr.Interface(
|
| 22 |
+
fn=recognize_captcha,
|
| 23 |
+
inputs=[
|
| 24 |
gr.Image,
|
| 25 |
gr.Dropdown(
|
| 26 |
['anuashok/ocr-captcha-v3','anuashok/ocr-captcha-v2','anuashok/ocr-captcha-v1'], label='Model to use'
|
| 27 |
)
|
| 28 |
],
|
| 29 |
+
outputs=['text'],
|
| 30 |
title = "character sequence recognition from scene-image (captcha)",
|
| 31 |
description = "Using some TrOCR models found on the HF Hub. Will you have to train your own?",
|
| 32 |
examples = ['','']
|