Skip to content

Commit

Permalink
Merge branch 'baidubce:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
barrierye authored Mar 8, 2024
2 parents 07c2325 + 6b61b5d commit d6ab119
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ AppBuilder SDK面向开发者提供AI原生应用一站式开发工具,包括
* 大模型组件新增:Excel2Figure(基于Excel信息画图表)
* AI能力引擎组件新增&更新:植物识别、动物识别、表格文字识别V2、手写文字识别、二维码识别、身份证混贴识别、文档矫正识别、图像内容理解、流式TTS
* AgentRuntime:新增[Cookbook](https://github.com/baidubce/app-builder/blob/master/cookbooks/agent_runtime.ipynb)
* **v0.4.1版本发布**
* 支持以下功能进行FunctionCall调用:动植物识别、表格文字识别、条形码及二维码识别、身份证混贴识别、手写文字识别、text2image、excel2figure

## 教程与文档

Expand Down
13 changes: 6 additions & 7 deletions appbuilder/core/components/handwrite_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from appbuilder.core.components.handwrite_ocr.model import *
from appbuilder.core.message import Message
from appbuilder.core._client import HTTPClient
from appbuilder.core import utils

class HandwriteOCR(Component):
r""" 手写文字识别组件
Expand Down Expand Up @@ -106,7 +107,10 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):
file_names = kwargs.get("files")
file_urls = kwargs.get("file_urls", {})
for file_name in file_names:
file_url = file_urls.get(file_name, None)
if utils.is_url(file_name):
file_url = file_name
else:
file_url = file_urls.get(file_name, None)
if file_url is None:
raise InvalidRequestArgumentError(f"file {file_name} url does not exist")
req = HandwriteOCRRequest()
Expand All @@ -116,12 +120,7 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):
req.detect_direction = "true"
req.detect_alteration = "true"
response = self._recognize(req)
out = HandwriteOCROutMsg()
out.direction = response.direction
[out.contents.append(
Content(text=w.words))
for w in response.words_result]
result[file_name] = out.dict()
result[file_name] = [w.words for w in response.words_result]

if streaming:
yield json.dumps(result, ensure_ascii=False)
Expand Down
7 changes: 6 additions & 1 deletion appbuilder/core/components/mix_card_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
r"""身份证混贴识别组件"""
import base64
import json

from appbuilder.core import utils
from appbuilder.core._client import HTTPClient
from appbuilder.core._exception import AppBuilderServerException, InvalidRequestArgumentError
from appbuilder.core.component import Component
Expand Down Expand Up @@ -154,7 +156,10 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):
file_names = kwargs.get("files")
file_urls = kwargs.get("file_urls", {})
for file_name in file_names:
file_url = file_urls.get(file_name, None)
if utils.is_url(file_name):
file_url = file_name
else:
file_url = file_urls.get(file_name, None)
if file_url is None:
raise InvalidRequestArgumentError(f"file {file_name} url does not exist")

Expand Down
8 changes: 6 additions & 2 deletions appbuilder/core/components/qrcode_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import base64
import json

from appbuilder.core import utils
from appbuilder.core.component import Component
from appbuilder.core.components.qrcode_ocr.model import *
from appbuilder.core.message import Message
Expand Down Expand Up @@ -154,7 +155,10 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):

file_urls = kwargs.get("file_urls", {})
for file_name in file_names:
file_url = file_urls.get(file_name, None)
if utils.is_url(file_name):
file_url = file_name
else:
file_url = file_urls.get(file_name, None)
if file_url is None:
raise InvalidRequestArgumentError(f"file {file_name} url does not exist")
req = QRcodeRequest()
Expand All @@ -163,7 +167,7 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):
raise InvalidRequestArgumentError("location must be a string with value 'true' or 'false'")
req.location = location
resp = self._recognize(req)
result[file_name] = proto.Message.to_dict(resp)["codes_result"]
result[file_name] = [item["text"] for item in proto.Message.to_dict(resp).get("codes_result", [])]
if streaming:
yield json.dumps(result, ensure_ascii=False)
else:
Expand Down
6 changes: 5 additions & 1 deletion appbuilder/core/components/table_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import base64
import json

from appbuilder.core import utils
from appbuilder.core.component import Component
from appbuilder.core.components.table_ocr.model import *
from appbuilder.core.message import Message
Expand Down Expand Up @@ -180,7 +181,10 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):
file_names = kwargs.get("files")
file_urls = kwargs.get("file_urls", {})
for file_name in file_names:
file_url = file_urls.get(file_name, None)
if utils.is_url(file_name):
file_url = file_name
else:
file_url = file_urls.get(file_name, None)
if file_url is None:
raise InvalidRequestArgumentError(f"file {file_name} url does not exist")
req = TableOCRRequest()
Expand Down
12 changes: 11 additions & 1 deletion appbuilder/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
import itertools
from typing import List

from urllib.parse import urlparse
from appbuilder.core._client import HTTPClient
from appbuilder.core._exception import TypeNotSupportedException, ModelNotSupportedException
from appbuilder.utils.model_util import GetModelListRequest, Models, model_name_mapping
Expand Down Expand Up @@ -63,6 +63,16 @@ def convert_cloudhub_url(client: HTTPClient, qianfan_url: str) -> str:
return "{}/{}{}".format(client.gateway, cloudhub_url_prefix, url_suffix)


def is_url(string):
"""
判断字符串是否是URL
:param string:
:return:
"""
result = urlparse(string)
return all([result.scheme, result.netloc])


class ModelInfo:
""" 模型信息类 """

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

setup(
name='appbuilder-sdk',
version='0.4.0',
version='0.4.1',
author='dongdaxiang',
author_email='[email protected]',
packages=find_packages(),
Expand Down

0 comments on commit d6ab119

Please sign in to comment.