zirui3 linjieccc commited on
Commit
3bf0069
·
0 Parent(s):

Duplicate from PaddlePaddle/ERNIE-Layout

Browse files

Co-authored-by: Linjie Chen <[email protected]>

Files changed (13) hide show
  1. .gitattributes +33 -0
  2. README.md +14 -0
  3. app.py +522 -0
  4. budget_form.png +3 -0
  5. custom_declaration_form.png +3 -0
  6. footer.html +4 -0
  7. header.html +31 -0
  8. invoice.jpg +0 -0
  9. medical_bill_2.jpg +0 -0
  10. poster.png +3 -0
  11. receipt.png +3 -0
  12. requirements.txt +5 -0
  13. resume.png +3 -0
.gitattributes ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.model filter=lfs diff=lfs merge=lfs -text
11
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
12
+ *.npy filter=lfs diff=lfs merge=lfs -text
13
+ *.npz filter=lfs diff=lfs merge=lfs -text
14
+ *.onnx filter=lfs diff=lfs merge=lfs -text
15
+ *.ot filter=lfs diff=lfs merge=lfs -text
16
+ *.parquet filter=lfs diff=lfs merge=lfs -text
17
+ *.pickle filter=lfs diff=lfs merge=lfs -text
18
+ *.pkl filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pt filter=lfs diff=lfs merge=lfs -text
21
+ *.pth filter=lfs diff=lfs merge=lfs -text
22
+ *.rar filter=lfs diff=lfs merge=lfs -text
23
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
24
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
25
+ *.tflite filter=lfs diff=lfs merge=lfs -text
26
+ *.tgz filter=lfs diff=lfs merge=lfs -text
27
+ *.wasm filter=lfs diff=lfs merge=lfs -text
28
+ *.xz filter=lfs diff=lfs merge=lfs -text
29
+ *.zip filter=lfs diff=lfs merge=lfs -text
30
+ *.zst filter=lfs diff=lfs merge=lfs -text
31
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
32
+ *.png filter=lfs diff=lfs merge=lfs -text
33
+ *.jpeg filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: ERNIE-Layout
3
+ emoji: 🧾
4
+ colorFrom: gray
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 3.4.1
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ duplicated_from: PaddlePaddle/ERNIE-Layout
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,522 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #-*- coding: UTF-8 -*-
2
+ # Copyright 2022 The Impira Team and the HuggingFace Team.
3
+ # Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ import os
18
+ import json
19
+ import base64
20
+ from io import BytesIO
21
+ from PIL import Image
22
+ import traceback
23
+
24
+ import requests
25
+ import numpy as np
26
+ import gradio as gr
27
+ import pdf2image
28
+ import fitz
29
+ import cv2
30
+
31
+ fitz_tools = fitz.Tools()
32
+
33
+
34
+ def pdf2img(stream, pagenos, dpi=300, thread_count=3, height=1600):
35
+ images = []
36
+ cimages = pdf2image.convert_from_bytes(
37
+ stream, dpi=dpi, thread_count=thread_count, first_page=pagenos[0] + 1, last_page=pagenos[-1] + 1,
38
+ size=height)
39
+ for _image in cimages:
40
+ image = np.array(_image)
41
+ image = image[..., ::-1]
42
+ images.append(image)
43
+ return images
44
+
45
+
46
+ class PdfReader(object):
47
+ """pdf reader"""
48
+ def __init__(self,
49
+ stream: bytes,
50
+ image_height: int = 1600):
51
+ self.stream = stream
52
+ self._image_height = image_height
53
+ self._dpi = 200
54
+ self._inpdf = self.load_file(stream)
55
+
56
+ @staticmethod
57
+ def load_file(stream):
58
+ """load document"""
59
+ try:
60
+ inpdf = fitz.Document(stream=stream, filetype="pdf")
61
+ except Exception as e:
62
+ print(f"[PDF_READER]-[Failed to load the file]-[{repr(e)}]")
63
+ return inpdf
64
+
65
+ @staticmethod
66
+ def _convert_page_obj_to_image(page_obj, image_height: int = None):
67
+ """fitz convert pdf to image
68
+
69
+ Args:
70
+ page_obj ([type]): [description]
71
+ ratio ([type]): [description]
72
+
73
+ Returns:
74
+ [type]: [description]
75
+ """
76
+ if image_height:
77
+ _, page_height = page_obj.rect.x1 - \
78
+ page_obj.rect.x0, page_obj.rect.y1 - page_obj.rect.y0
79
+ ratio = image_height / page_height
80
+ else:
81
+ ratio = 1.0
82
+ trans = fitz.Matrix(ratio, ratio)
83
+ pixmap = page_obj.get_pixmap(matrix=trans, alpha=False)
84
+ image = cv2.imdecode(np.frombuffer(pixmap.tobytes(), np.uint8), -1)
85
+ fitz_tools.store_shrink(100)
86
+ return image
87
+
88
+ def get_page_image(self,
89
+ pageno):
90
+ """get page image
91
+
92
+ Args:
93
+ pageno ([type]): [description]
94
+
95
+ Returns:
96
+ [type]: [description]
97
+ """
98
+ try:
99
+ page_obj = self._inpdf[pageno]
100
+ return self._convert_page_obj_to_image(page_obj, self._image_height)
101
+ except Exception as e:
102
+ print(f"[Failed to convert the PDF to images]-[{repr(e)}]")
103
+ try:
104
+ return pdf2img(stream=self.stream,
105
+ pagenos=[pageno],
106
+ height=self._image_height,
107
+ dpi=self._dpi)[0]
108
+ except Exception as e:
109
+ print(f"[Failed to convert the PDF to images]-[{repr(e)}]")
110
+ return None
111
+
112
+
113
+ examples = [
114
+ [
115
+ "budget_form.png",
116
+ "What is the total actual and/or obligated expenses of ECG Center?"
117
+ ],
118
+ [
119
+ "poster.png",
120
+ "Which gift idea needs a printer?"
121
+ ],
122
+ [
123
+ "receipt.png",
124
+ "เบอร์โทรร้านอะไรคะ?"
125
+ ],
126
+ [
127
+ "medical_bill_2.jpg",
128
+ "患者さんは何でお金を払いますか。"
129
+ ],
130
+ [
131
+ "resume.png",
132
+ "五百丁本次想要担任的是什么职位?",
133
+ ],
134
+ [
135
+ "custom_declaration_form.png",
136
+ "在哪个口岸进口?"
137
+ ],
138
+ [
139
+ "invoice.jpg",
140
+ "发票号码是多少?",
141
+ ],
142
+ ]
143
+
144
+ prompt_files = {
145
+ "发票号码是多少?": "invoice.jpg",
146
+ "五百丁本次想要担任的是什么职位?": "resume.png",
147
+ "在哪个口岸进口?": "custom_declaration_form.png",
148
+ "What is the total actual and/or obligated expenses of ECG Center?": "budget_form.png",
149
+ "Which gift idea needs a printer?": "poster.png",
150
+ "患者さんは何でお金を払いますか。": "medical_bill_2.jpg",
151
+ "เบอร์โทรร้านอะไรคะ?": "receipt.png",
152
+ }
153
+
154
+ lang_map = {
155
+ "invoice.jpg": "ch",
156
+ "resume.png": "ch",
157
+ "custom_declaration_form.png": "ch",
158
+ "medical_bill_1.png": "ch",
159
+ "budget_form.png": "en",
160
+ "website_design_guide.jpeg": "en",
161
+ "poster.png": "en",
162
+ "medical_bill_2.jpg": "ch",
163
+ "receipt.png": "en"
164
+ }
165
+
166
+
167
+ def load_document(path):
168
+ if path.startswith("http://") or path.startswith("https://"):
169
+ resp = requests.get(path, allow_redirects=True, stream=True)
170
+ b = resp.raw
171
+ else:
172
+ b = open(path, "rb")
173
+
174
+ if path.endswith(".pdf"):
175
+ images_list = []
176
+ pdfreader = PdfReader(stream=b.read())
177
+ for p_no in range(0, pdfreader._inpdf.page_count):
178
+ img_np = pdfreader.get_page_image(pageno=p_no)
179
+ images_list.append(img_np)
180
+ else:
181
+ image = Image.open(b)
182
+ images_list = [np.array(image.convert("RGB"))]
183
+ return images_list
184
+
185
+ def process_path(path):
186
+ error = None
187
+ if path:
188
+ try:
189
+ images_list = load_document(path)
190
+ return (
191
+ path,
192
+ gr.update(visible=True, value=images_list),
193
+ gr.update(visible=True),
194
+ gr.update(visible=False, value=None),
195
+ gr.update(visible=False, value=None),
196
+ None,
197
+ )
198
+ except Exception as e:
199
+ traceback.print_exc()
200
+ error = str(e)
201
+ return (
202
+ None,
203
+ gr.update(visible=False, value=None),
204
+ gr.update(visible=False),
205
+ gr.update(visible=False, value=None),
206
+ gr.update(visible=False, value=None),
207
+ gr.update(visible=True, value=error) if error is not None else None,
208
+ None,
209
+ )
210
+
211
+
212
+ def process_upload(file):
213
+ if file:
214
+ return process_path(file.name)
215
+ else:
216
+ return (
217
+ None,
218
+ gr.update(visible=False, value=None),
219
+ gr.update(visible=False),
220
+ gr.update(visible=False, value=None),
221
+ gr.update(visible=False, value=None),
222
+ None,
223
+ )
224
+
225
+
226
+ def np2base64(image_np):
227
+ image = cv2.imencode('.jpg', image_np)[1]
228
+ base64_str = str(base64.b64encode(image))[2:-1]
229
+ return base64_str
230
+
231
+
232
+ def get_base64(path):
233
+ if path.startswith("http://") or path.startswith("https://"):
234
+ resp = requests.get(path, allow_redirects=True, stream=True)
235
+ b = resp.raw
236
+ else:
237
+ b = open(path, "rb")
238
+
239
+ if path.endswith(".pdf"):
240
+ images_list = []
241
+ pdfreader = PdfReader(stream=b.read())
242
+ for p_no in range(0, min(pdfreader._inpdf.page_count, 1)):
243
+ img_np = pdfreader.get_page_image(pageno=p_no)
244
+ images_list.append(img_np)
245
+ base64_str = np2base64(images_list[0])
246
+ else:
247
+ base64_str = base64.b64encode(b.read()).decode()
248
+ return base64_str
249
+
250
+
251
+ def process_prompt(prompt, document, lang="ch", model="docprompt_v1"):
252
+ if not prompt:
253
+ prompt = "What is the total actual and/or obligated expenses of ECG Center?"
254
+ if document is None:
255
+ return None, None, None
256
+
257
+ access_token = os.environ['token']
258
+ url = f"https://aip.baidubce.com/rpc/2.0/nlp-itec/poc/docprompt?access_token={access_token}"
259
+
260
+ base64_str = get_base64(document)
261
+
262
+ r = requests.post(url, json={"doc": base64_str, "prompt": [prompt], "lang": lang, "model": model})
263
+ response = r.json()
264
+ predictions = response['result']
265
+ img_list = response['image']
266
+ pages = [Image.open(BytesIO(base64.b64decode(img))) for img in img_list]
267
+
268
+ text_value = predictions[0]['result'][0]['value']
269
+
270
+ return (
271
+ gr.update(visible=True, value=pages),
272
+ gr.update(visible=True, value=predictions),
273
+ gr.update(
274
+ visible=True,
275
+ value=text_value,
276
+ ),
277
+ )
278
+
279
+
280
+ def load_example_document(img, prompt):
281
+ if img is not None:
282
+ document = prompt_files[prompt]
283
+ lang = lang_map[document]
284
+ preview, answer, answer_text = process_prompt(prompt, document, lang, "docprompt_v1")
285
+ return document, prompt, preview, gr.update(visible=True), answer, answer_text
286
+ else:
287
+ return None, None, None, gr.update(visible=False), None, None
288
+
289
+
290
+ def read_content(file_path: str) -> str:
291
+ """read the content of target file
292
+ """
293
+ with open(file_path, 'r', encoding='utf-8') as f:
294
+ content = f.read()
295
+
296
+ return content
297
+
298
+
299
+ CSS = """
300
+ #prompt input {
301
+ font-size: 16px;
302
+ }
303
+ #url-textbox {
304
+ padding: 0 !important;
305
+ }
306
+ #short-upload-box .w-full {
307
+ min-height: 10rem !important;
308
+ }
309
+ /* I think something like this can be used to re-shape
310
+ * the table
311
+ */
312
+ /*
313
+ .gr-samples-table tr {
314
+ display: inline;
315
+ }
316
+ .gr-samples-table .p-2 {
317
+ width: 100px;
318
+ }
319
+ */
320
+ #select-a-file {
321
+ width: 100%;
322
+ }
323
+ #file-clear {
324
+ padding-top: 2px !important;
325
+ padding-bottom: 2px !important;
326
+ padding-left: 8px !important;
327
+ padding-right: 8px !important;
328
+ margin-top: 10px;
329
+ }
330
+ .gradio-container .gr-button-primary {
331
+ background: linear-gradient(180deg, #CDF9BE 0%, #AFF497 100%);
332
+ border: 1px solid #B0DCCC;
333
+ border-radius: 8px;
334
+ color: #1B8700;
335
+ }
336
+ .gradio-container.dark button#submit-button {
337
+ background: linear-gradient(180deg, #CDF9BE 0%, #AFF497 100%);
338
+ border: 1px solid #B0DCCC;
339
+ border-radius: 8px;
340
+ color: #1B8700
341
+ }
342
+ table.gr-samples-table tr td {
343
+ border: none;
344
+ outline: none;
345
+ }
346
+ table.gr-samples-table tr td:first-of-type {
347
+ width: 0%;
348
+ }
349
+ div#short-upload-box div.absolute {
350
+ display: none !important;
351
+ }
352
+ gradio-app > div > div > div > div.w-full > div, .gradio-app > div > div > div > div.w-full > div {
353
+ gap: 0px 2%;
354
+ }
355
+ gradio-app div div div div.w-full, .gradio-app div div div div.w-full {
356
+ gap: 0px;
357
+ }
358
+ gradio-app h2, .gradio-app h2 {
359
+ padding-top: 10px;
360
+ }
361
+ #answer {
362
+ overflow-y: scroll;
363
+ color: white;
364
+ background: #666;
365
+ border-color: #666;
366
+ font-size: 20px;
367
+ font-weight: bold;
368
+ }
369
+ #answer span {
370
+ color: white;
371
+ }
372
+ #answer textarea {
373
+ color:white;
374
+ background: #777;
375
+ border-color: #777;
376
+ font-size: 18px;
377
+ }
378
+ #url-error input {
379
+ color: red;
380
+ }
381
+ """
382
+
383
+ with gr.Blocks(css=CSS) as demo:
384
+ gr.HTML(read_content("header.html"))
385
+ gr.Markdown(
386
+ "DocPrompt🔖 is a Document Prompt Engine using ERNIE-Layout as the backbone model."
387
+ "The engine is powered by BAIDU WenXin Document Intelligence Team "
388
+ "and has the ability for multilingual documents information extraction and question ansering. "
389
+ "For more details, please visit the [Github](https://github.com/PaddlePaddle/PaddleNLP/tree/develop/model_zoo/ernie-layout)."
390
+ "ERNIE-Layout paper please refer to [ERNIE-Layout](https://paperswithcode.com/paper/ernie-layout-layout-knowledge-enhanced-pre)"
391
+ )
392
+
393
+ document = gr.Variable()
394
+ example_prompt = gr.Textbox(visible=False)
395
+ example_image = gr.Image(visible=False)
396
+ with gr.Row(equal_height=True):
397
+ with gr.Column():
398
+ with gr.Row():
399
+ gr.Markdown("## 1. Select a file", elem_id="select-a-file")
400
+ img_clear_button = gr.Button(
401
+ "Clear", variant="secondary", elem_id="file-clear", visible=False
402
+ )
403
+ image = gr.Gallery(visible=False)
404
+ with gr.Row(equal_height=True):
405
+ with gr.Column():
406
+ with gr.Row():
407
+ url = gr.Textbox(
408
+ show_label=False,
409
+ placeholder="URL",
410
+ lines=1,
411
+ max_lines=1,
412
+ elem_id="url-textbox",
413
+ )
414
+ submit = gr.Button("Get")
415
+ url_error = gr.Textbox(
416
+ visible=False,
417
+ elem_id="url-error",
418
+ max_lines=1,
419
+ interactive=False,
420
+ label="Error",
421
+ )
422
+ gr.Markdown("— or —")
423
+ upload = gr.File(label=None, interactive=True, elem_id="short-upload-box")
424
+ gr.Examples(
425
+ examples=examples,
426
+ inputs=[example_image, example_prompt],
427
+ )
428
+
429
+ with gr.Column() as col:
430
+ gr.Markdown("## 2. Make a request")
431
+ prompt = gr.Textbox(
432
+ label="Prompt (No restrictions on the setting of prompt. You can type any prompt.)",
433
+ placeholder="e.g. What is the total actual and/or obligated expenses of ECG Center?",
434
+ lines=1,
435
+ max_lines=1,
436
+ )
437
+ ocr_lang = gr.Radio(
438
+ choices=["ch", "en"],
439
+ value="en",
440
+ label="Select OCR Language (Please choose ch for Chinese images.)",
441
+ )
442
+ model = gr.Radio(
443
+ choices=["docprompt_v1", "docprompt_v2"],
444
+ value="docprompt_v1",
445
+ label="Select Inference Model.",
446
+ )
447
+
448
+ with gr.Row():
449
+ clear_button = gr.Button("Clear", variant="secondary")
450
+ submit_button = gr.Button(
451
+ "Submit", variant="primary", elem_id="submit-button"
452
+ )
453
+ with gr.Column():
454
+ output_text = gr.Textbox(
455
+ label="Top Answer", visible=False, elem_id="answer"
456
+ )
457
+ output = gr.JSON(label="Output", visible=False)
458
+
459
+ for cb in [img_clear_button, clear_button]:
460
+ cb.click(
461
+ lambda _: (
462
+ gr.update(visible=False, value=None),
463
+ None,
464
+ gr.update(visible=False, value=None),
465
+ gr.update(visible=False, value=None),
466
+ gr.update(visible=False),
467
+ None,
468
+ None,
469
+ None,
470
+ gr.update(visible=False, value=None),
471
+ None,
472
+ ),
473
+ inputs=clear_button,
474
+ outputs=[
475
+ image,
476
+ document,
477
+ output,
478
+ output_text,
479
+ img_clear_button,
480
+ example_image,
481
+ upload,
482
+ url,
483
+ url_error,
484
+ prompt,
485
+ ],
486
+ )
487
+
488
+ upload.change(
489
+ fn=process_upload,
490
+ inputs=[upload],
491
+ outputs=[document, image, img_clear_button, output, output_text, url_error],
492
+ )
493
+ submit.click(
494
+ fn=process_path,
495
+ inputs=[url],
496
+ outputs=[document, image, img_clear_button, output, output_text, url_error],
497
+ )
498
+
499
+ prompt.submit(
500
+ fn=process_prompt,
501
+ inputs=[prompt, document, ocr_lang, model],
502
+ outputs=[image, output, output_text],
503
+ )
504
+
505
+ submit_button.click(
506
+ fn=process_prompt,
507
+ inputs=[prompt, document, ocr_lang, model],
508
+ outputs=[image, output, output_text],
509
+ )
510
+
511
+ example_image.change(
512
+ fn=load_example_document,
513
+ inputs=[example_image, example_prompt],
514
+ outputs=[document, prompt, image, img_clear_button, output, output_text],
515
+ )
516
+
517
+ gr.Markdown("[![Stargazers repo roster for @PaddlePaddle/PaddleNLP](https://reporoster.com/stars/PaddlePaddle/PaddleNLP)](https://github.com/PaddlePaddle/PaddleNLP)")
518
+ gr.HTML(read_content("footer.html"))
519
+
520
+
521
+ if __name__ == "__main__":
522
+ demo.launch(enable_queue=False)
budget_form.png ADDED

Git LFS Details

  • SHA256: f9d225264f2120e4d2a971174183770e757ceb0c1b7d19bf72aee8eca22491e3
  • Pointer size: 131 Bytes
  • Size of remote file: 598 kB
custom_declaration_form.png ADDED

Git LFS Details

  • SHA256: 2835946f967dc794c6b3d0cf74a9d10c82f647fd007a7f0343a66b90d7b7495f
  • Pointer size: 130 Bytes
  • Size of remote file: 57 kB
footer.html ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ <div class="footer">
2
+ <p>Model by <a href="https://github.com/PaddlePaddle/PaddleNLP" style="text-decoration: underline;" target="_blank">PaddleNLP</a> - Gradio Demo by 🤗 Hugging Face
3
+ </p>
4
+ </div>
header.html ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
2
+ <div
3
+ style="
4
+ display: inline-flex;
5
+ gap: 0.8rem;
6
+ font-size: 1.75rem;
7
+ margin-bottom: 10px;
8
+ margin-left: 220px;
9
+ justify-content: center;
10
+ "
11
+ >
12
+ <a href="https://github.com/PaddlePaddle/PaddleNLP"><img src="https://user-images.githubusercontent.com/1371212/175816733-8ec25eb0-9af3-4380-9218-27c154518258.png" alt="PaddleNLP" width="60%"></a>
13
+ </div>
14
+ <div
15
+ style="
16
+ display: inline-flex;
17
+ align-items: center;
18
+ gap: 0.8rem;
19
+ font-size: 1.75rem;
20
+ margin-bottom: 10px;
21
+ justify-content: center;
22
+ ">
23
+ <a href="https://github.com/PaddlePaddle/PaddleNLP/tree/develop/model_zoo/ernie-layout"><h1 style="font-weight: 900; align-items: center; margin-bottom: 7px;">
24
+ ERNIE-Layout DocPrompt Engine 🧾
25
+ </h1></a>
26
+ </div>
27
+ <!-- <p style="margin-bottom: 10px; font-size: 94%">
28
+ DocPrompt🔖 is a Document Prompt Engine using [ERNIE-Layout](https://github.com/PaddlePaddle/PaddleNLP/tree/develop/model_zoo/ernie-layout) as the backbone model. The engine is powered by BAIDU WenXin Document Intelligence Team and has the ability for multilingual documents information extraction and question ansering.
29
+ </p> -->
30
+ <a href="https://github.com/PaddlePaddle/PaddleNLP"><img src="https://user-images.githubusercontent.com/40840292/195516769-c4452d7c-3f9e-446f-8f9d-882b99052a5b.png" width="100%"></a>
31
+ </div>
invoice.jpg ADDED
medical_bill_2.jpg ADDED
poster.png ADDED

Git LFS Details

  • SHA256: 13ca416998fc110bd6691b82759e0c53f1f95563c670d1aba157701ed8418386
  • Pointer size: 132 Bytes
  • Size of remote file: 2.24 MB
receipt.png ADDED

Git LFS Details

  • SHA256: 16c50c1952f4c4fa752d36f10f245175c769c8947472cac7059ab58ba5ad95ea
  • Pointer size: 131 Bytes
  • Size of remote file: 455 kB
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ numpy
2
+ opencv-python
3
+ pdf2image
4
+ PyMuPDF
5
+ requests
resume.png ADDED

Git LFS Details

  • SHA256: 7be8498397a59f6aedf3cbee96041aea96b5d8f1aa667cf1d3ac5e93a7716734
  • Pointer size: 131 Bytes
  • Size of remote file: 191 kB