""" Donut Copyright (c) 2022-present NAVER Corp. MIT License """ import argparse import gradio as gr import torch from donut import DonutModel def demo_process(input_img): global pretrained_model, task_prompt, task_name output = pretrained_model.inference(image=input_img, prompt=task_prompt)["predictions"][0] return output["text_sequence"].replace(" ", "") # temp task_prompt = f"" pretrained_model = DonutModel.from_pretrained("naver-clova-ix/donut-base-finetuned-kuzushiji") pretrained_model.eval() demo = gr.Interface( fn=demo_process, inputs= gr.inputs.Image(type="pil"), outputs="text", title=f"Donut 🍩 demonstration for Kuzushiji Decoding", description="""This is a toy example for decoding kuzushiji (old Japanese cursive characters, γγšγ—ε­—) documents with a single E2E model, `Document Understanding Transformer` (Donut 🍩, ECCV-22). This particular model is fine-tuned on Kuzushiji Dataset. To use it, simply upload a kuzushiji document image or use one of the examples below and click `Submit`. Results will show up in a few seconds.
* Note that this demo is running on a small resource environment, `basic CPU plan` (`2 vCPU, 16GiB RAM`).
* Demonstrations for other types of documents/tasks are available at https://github.com/clovaai/donut
* More details of Donut are available at Paper, GitHub, and Huggingface πŸ€— Implementation Page.
* Kuzushiji Dataset is from Dataset Link (Reference: γ€Žζ—₯ζœ¬ε€ε…Έη±γγšγ—ε­—γƒ‡γƒΌγ‚Ώγ‚»γƒƒγƒˆγ€οΌˆε›½ζ–‡η ”γ»γ‹ζ‰€θ”΅οΌCODH加ε·₯οΌ‰doi:10.20676/00000340).""", examples=[["sample1.jpg"], ["sample2.jpg"]], cache_examples=False, ) demo.launch()