laverdes commited on
Commit
6581de9
·
1 Parent(s): 769783b

feat: app.py created with text and imports

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ from PIL import Image
4
+ from transformers import VisionEncoderDecoderModel, VisionEncoderDecoderConfig # , DonutProcessor
5
+
6
+
7
+ def demo_process(input_img):
8
+ global pretrained_model, task_prompt, task_name
9
+ # input_img = Image.fromarray(input_img)
10
+ output = pretrained_model.inference(image=input_img, prompt=task_prompt)["predictions"][0]
11
+ return output
12
+
13
+ task_prompt = f"<s>"
14
+
15
+ st.text('This model is trained with receipt images -> SROIE dataset.')
16
+
17
+ """image = Image.open("./sample_image_1.png")
18
+ image.save("receipt1.png")
19
+ image = Image.open("./sample_image_2.png")
20
+ image.save("receipt2.png")
21
+
22
+ pretrained_model = VisionEncoderDecoderModel.from_pretrained("unstructured/donut-base-sroie")
23
+ pretrained_model.encoder.to(torch.bfloat16)
24
+ pretrained_model.eval()
25
+
26
+ # replace for streamlit widgets
27
+ demo = gr.Interface(
28
+ fn=demo_process,
29
+ inputs= gr.inputs.Image(type="pil"),
30
+ outputs="json",
31
+ title=f"Donut 🍩 demonstration for `cord-v2` task",
32
+ description="""This model is trained with 800 Indonesian receipt images of CORD dataset. <br>
33
+ Demonstrations for other types of documents/tasks are available at https://github.com/clovaai/donut <br>
34
+ More CORD receipt images are available at https://huggingface.co/datasets/naver-clova-ix/cord-v2
35
+ More details are available at:
36
+ - Paper: https://arxiv.org/abs/2111.15664
37
+ - GitHub: https://github.com/clovaai/donut""",
38
+ examples=[["receipt1.png"], ["receipt2.png"]],
39
+ cache_examples=False,
40
+ )
41
+
42
+ demo.launch()"""