Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	File size: 1,339 Bytes
			
			| b50c8d8 3f7f130 9b5b062 b50c8d8 3f7f130 4fcbda4 3f7f130 c1669c3 3f7f130 c1669c3 0b75f14 3f7f130 0c14060 3f7f130 c1669c3 0d3b96f 8665656 46b5fd7 0c14060 9c65463 0c14060 3f7f130 0d3b96f 3f7f130 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import gradio as gr
from transformers import VisionEncoderDecoderModel, TrOCRProcessor
import torch
from PIL import Image
def recognize_captcha(input, mdl):
    
    # Load model and processor
    processor = TrOCRProcessor.from_pretrained(mdl)
    model = VisionEncoderDecoderModel.from_pretrained(mdl)
    
    # Prepare image
    pixel_values = processor(input, return_tensors="pt").pixel_values
    # Generate text
    generated_ids = model.generate(pixel_values)
    generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
    
    return generated_text
iface = gr.Interface(
    fn=recognize_captcha,
    inputs=[
        gr.Image(),
        gr.Dropdown(
            ['anuashok/ocr-captcha-v3','anuashok/ocr-captcha-v2','anuashok/ocr-captcha-v1','microsoft/trocr-base-printed'], label='Model to use'
        )
    ],
    outputs=['text'],
    title  = "Character Sequence Recognition From Captcha Image",
    description = "Using some TrOCR models found on the HF Hub to test/break tough text captchas. Will you have to train your own?",
    examples = [
        ['krcx5.jpg','anuashok/ocr-captcha-v3'],
        ['hyp2a.jpg','microsoft/trocr-base-printed'],
        ['k4kyf.jpg','anuashok/ocr-captcha-v2']
    ],
    article="Created by JSGR with ❤️ !!!"
)
iface.queue(max_size=10)
iface.launch()
 | 
