linjieccc commited on
Commit
01bf385
1 Parent(s): cee9c65
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -15,8 +15,10 @@
15
  # limitations under the License.
16
 
17
  import traceback
 
18
 
19
  import gradio as gr
 
20
 
21
  from paddlenlp import Taskflow
22
  from paddlenlp.utils.doc_parser import DocParser
@@ -83,6 +85,12 @@ def dbc2sbc(s):
83
  return rs
84
 
85
 
 
 
 
 
 
 
86
  def process_path(path):
87
  error = None
88
  if path:
@@ -179,8 +187,13 @@ def process_doc(document, schema, ocr_lang, layout_analysis):
179
  }
180
  prediction = run_taskflow(document, schema, argument)[0]
181
 
 
 
 
 
 
182
  img_show = doc_parser.write_image_with_results(
183
- document,
184
  result=prediction,
185
  return_image=True)
186
  img_list = [img_show]
 
15
  # limitations under the License.
16
 
17
  import traceback
18
+ import base64
19
 
20
  import gradio as gr
21
+ import cv2
22
 
23
  from paddlenlp import Taskflow
24
  from paddlenlp.utils.doc_parser import DocParser
 
85
  return rs
86
 
87
 
88
+ def np2base64(image_np):
89
+ image = cv2.imencode('.jpg', image_np)[1]
90
+ base64_str = str(base64.b64encode(image))[2:-1]
91
+ return base64_str
92
+
93
+
94
  def process_path(path):
95
  error = None
96
  if path:
 
187
  }
188
  prediction = run_taskflow(document, schema, argument)[0]
189
 
190
+ if document.endswith(".pdf"):
191
+ _image = doc_parser.read_pdf(document)
192
+ else:
193
+ _image = doc_parser.read_image(document)
194
+
195
  img_show = doc_parser.write_image_with_results(
196
+ np2base64(_image),
197
  result=prediction,
198
  return_image=True)
199
  img_list = [img_show]