Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel | |
import requests | |
from PIL import Image | |
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-printed") | |
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-printed") | |
def process_image(image): | |
# prepare image | |
pixel_values = processor(image, return_tensors="pt").pixel_values | |
# generate (no beam search) | |
generated_ids = model.generate(pixel_values) | |
# decode | |
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0] | |
return generated_text | |
title = "Demo: TrOCR" | |
#css = """.output_image, .input_image {height: 600px !important}""" | |
iface = gr.Interface( | |
fn=process_image, | |
inputs=gr.inputs.Image(type="pil"), | |
outputs=gr.outputs.Textbox(), | |
title=title, | |
) | |
iface.launch(debug=True) |