commit 65062acfcea3ac81c5451abca411ac0792e67956 Author: SOULOFCINDER <841135647@qq.com> Date: Thu Mar 30 11:36:03 2023 +0800 inital diff --git a/trocr_small_handwritten/app.py b/trocr_small_handwritten/app.py new file mode 100644 index 0000000..7c08d26 --- /dev/null +++ b/trocr_small_handwritten/app.py @@ -0,0 +1,33 @@ +import gradio as gr +from PIL import Image +from transformers import TrOCRProcessor, VisionEncoderDecoderModel + + +def inference(img): + pretrained_model_path = "trocr-small-handwritten" + image = img.convert("RGB") + + processor = TrOCRProcessor.from_pretrained(pretrained_model_path) + model = VisionEncoderDecoderModel.from_pretrained(pretrained_model_path) + pixel_values = processor(images=image, return_tensors="pt").pixel_values + + generated_ids = model.generate(pixel_values) + generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0] + print(generated_text) + +title = "OCR:trocr-small-handwritten" +description = "Gradio Demo for trocr-small-handwritten. To use it, simply upload your image, or click one of the examples to load them." +article = "