Spaces:
Runtime error
Runtime error
| import torch | |
| from PIL import Image | |
| from transformers import VisionEncoderDecoderModel, VisionEncoderDecoderConfig # , DonutProcessor | |
| def demo_process(input_img): | |
| global pretrained_model, task_prompt, task_name | |
| # input_img = Image.fromarray(input_img) | |
| output = pretrained_model.inference(image=input_img, prompt=task_prompt)["predictions"][0] | |
| return output | |
| task_prompt = f"<s>" | |
| st.text('This model is trained with receipt images -> SROIE dataset.') | |
| """image = Image.open("./sample_image_1.png") | |
| image.save("receipt1.png") | |
| image = Image.open("./sample_image_2.png") | |
| image.save("receipt2.png") | |
| pretrained_model = VisionEncoderDecoderModel.from_pretrained("unstructured/donut-base-sroie") | |
| pretrained_model.encoder.to(torch.bfloat16) | |
| pretrained_model.eval() | |
| # replace for streamlit widgets | |
| demo = gr.Interface( | |
| fn=demo_process, | |
| inputs= gr.inputs.Image(type="pil"), | |
| outputs="json", | |
| title=f"Donut 🍩 demonstration for `cord-v2` task", | |
| description="""This model is trained with 800 Indonesian receipt images of CORD dataset. <br> | |
| Demonstrations for other types of documents/tasks are available at https://github.com/clovaai/donut <br> | |
| More CORD receipt images are available at https://huggingface.co/datasets/naver-clova-ix/cord-v2 | |
| More details are available at: | |
| - Paper: https://arxiv.org/abs/2111.15664 | |
| - GitHub: https://github.com/clovaai/donut""", | |
| examples=[["receipt1.png"], ["receipt2.png"]], | |
| cache_examples=False, | |
| ) | |
| demo.launch()""" | |