Spaces:
Sleeping
Sleeping
File size: 876 Bytes
6b1ed35 0ca5f4d 6b1ed35 f0064ac 6b1ed35 3d68599 6b1ed35 37c49d0 61eaaa0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from transformers import VisionEncoderDecoderModel
from transformers import TrOCRProcessor, AutoTokenizer, ViTImageProcessor
import gradio as gr
from PIL import Image
def OCR(image):
model = VisionEncoderDecoderModel.from_pretrained("kavg/TrOCR-SIN")
tokenizer = AutoTokenizer.from_pretrained('NLPC-UOM/SinBERT-large')
feature_extractor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224")
processor = TrOCRProcessor(image_processor=feature_extractor, tokenizer=tokenizer)
pixel_values = processor(image, return_tensors="pt").pixel_values
generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
return generated_text
demo = gr.Interface(fn=OCR, inputs=gr.Image(show_label=False, type="pil"),outputs=gr.Textbox())
demo.launch(debug=True) |