Spaces:
Runtime error
Runtime error
gwkrsrch
commited on
Commit
·
c413da6
1
Parent(s):
a4cb68c
init
Browse files- app.py +33 -0
- requirements.txt +3 -0
- sample1.jpg +0 -0
- sample2.jpg +0 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Donut
|
3 |
+
Copyright (c) 2022-present NAVER Corp.
|
4 |
+
MIT License
|
5 |
+
"""
|
6 |
+
import argparse
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
import torch
|
10 |
+
|
11 |
+
from donut import DonutModel
|
12 |
+
|
13 |
+
def demo_process(input_img):
|
14 |
+
global pretrained_model, task_prompt, task_name
|
15 |
+
output = pretrained_model.inference(image=input_img, prompt=task_prompt)["predictions"][0]
|
16 |
+
return output["text_sequence"].replace(" ", "") # temp
|
17 |
+
|
18 |
+
task_prompt = f"<s_kuzushiji>"
|
19 |
+
pretrained_model = DonutModel.from_pretrained("naver-clova-ix/donut-base-finetuned-kuzushiji")
|
20 |
+
pretrained_model.eval()
|
21 |
+
|
22 |
+
demo = gr.Interface(
|
23 |
+
fn=demo_process,
|
24 |
+
inputs= gr.inputs.Image(type="pil"),
|
25 |
+
outputs="text",
|
26 |
+
title=f"Donut 🍩 demonstration for Kuzushiji Decoding",
|
27 |
+
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 <a href="http://codh.rois.ac.jp/char-shape/">Kuzushiji Dataset</a>. 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.<br>* Note that this demo is running on a small resource environment, `basic CPU plan` (`2 vCPU, 16GiB RAM`).<br>* Demonstrations for other types of documents/tasks are available at https://github.com/clovaai/donut<br>
|
28 |
+
* More details of Donut are available at <a href="https://arxiv.org/abs/2111.15664">Paper</a>, <a href="https://github.com/clovaai/donut">GitHub</a>, and <a href="https://huggingface.co/docs/transformers/model_doc/donut">Huggingface 🤗 Implementation Page</a>.<br>
|
29 |
+
* Kuzushiji Dataset is from <a href="http://codh.rois.ac.jp/char-shape/">Dataset Link</a> (Reference: 『日本古典籍くずし字データセット』(国文研ほか所蔵/CODH加工)doi:10.20676/00000340).""",
|
30 |
+
examples=[["sample1.jpg"], ["sample2.jpg"]],
|
31 |
+
cache_examples=False,
|
32 |
+
)
|
33 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
donut-python
|
3 |
+
gradio
|
sample1.jpg
ADDED
![]() |
sample2.jpg
ADDED
![]() |