Add uie python example and doc (#221)

* add fastdeploy.text.UIEModel

* Add uie python example

* Add one schema for cpp demo

* Add ConvertUIEResultToDict for pretty the uie result in python

* remove default args for SchemaNode

* Add uie example args

* Add uie python api desc

* Add infer.py usage

* truncate some example output

* Add uie schema usage

* Add uie result md

* Add uie c++ api doc
This commit is contained in:
Jack Zhou
2022-09-15 06:06:40 +08:00
committed by GitHub
parent fb0a428c3c
commit 14ba9ce6c2
11 changed files with 760 additions and 33 deletions

View File

@@ -14,3 +14,4 @@
from __future__ import absolute_import
from . import uie
from .uie import UIEModel

View File

@@ -23,11 +23,13 @@ from ... import c_lib_wrap as C
class SchemaNode(object):
def __init__(self, name, children=[]):
schema_node_children = []
if isinstance(children, str):
children = [children]
for child in children:
if isinstance(child, str):
schema_node_children += [C.text.SchemaNode(child, [])]
elif isinstance(child, dict):
for key, val in child.item():
for key, val in child.items():
schema_node_child = SchemaNode(key, val)
schema_node_children += [schema_node_child._schema_node]
else:
@@ -69,5 +71,15 @@ class UIEModel(object):
schema = schema_tmp
self._model.set_schema(schema)
def predict(self, texts):
return self._model.predict(texts)
def predict(self, texts, return_dict=False):
results = self._model.predict(texts)
if not return_dict:
return results
new_results = []
for result in results:
uie_result = dict()
for key, uie_results in result.items():
for uie_res in uie_results:
uie_result[key] = uie_res.get_dict()
new_results += [uie_result]
return new_results