xubo пре 1 година
родитељ
комит
05cc904b9a

+ 7 - 0
.gitignore

@@ -0,0 +1,7 @@
+runtime/
+.idea/
+.vscode/
+__pycache__/
+.pytest_cache/
+.idea
+venv

+ 61 - 0
alibabacloud_sample.egg-info/PKG-INFO

@@ -0,0 +1,61 @@
+Metadata-Version: 2.1
+Name: alibabacloud-sample
+Version: 1.0.0
+Summary: Alibaba Cloud SDK Code Sample Library for Python
+Home-page: https://github.com/aliyun/alibabacloud-sdk
+Author: 
+Author-email: 
+License: Apache License 2.0
+Keywords: alibabacloud,sample
+Platform: any
+Classifier: Development Status :: 4 - Beta
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: Apache Software License
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.6
+Classifier: Programming Language :: Python :: 3.7
+Classifier: Programming Language :: Python :: 3.8
+Classifier: Programming Language :: Python :: 3.9
+Classifier: Topic :: Software Development
+Requires-Python: >=3.6
+Description-Content-Type: text/markdown
+Requires-Dist: alibabacloud_ocr-api20210707<3.0.0,>=2.0.8
+Requires-Dist: alibabacloud_tea_openapi<1.0.0,>=0.3.8
+Requires-Dist: alibabacloud_tea_console<1.0.0,>=0.0.1
+Requires-Dist: alibabacloud_tea_util<1.0.0,>=0.3.11
+Requires-Dist: alibabacloud_darabonba_stream<1.0.0,>=0.0.1
+
+# OCR统一识别文档示例
+
+该项目为OCR统一识别接口支持识别多种图片类型,包括通用文字、个人卡证、发票等。您只需要通过Type参数指定图片类型,无须更换接口。文档示例,该示例**无法在线调试**,如需调试可下载到本地后替换 [AK](https://usercenter.console.aliyun.com/#/manage/ak) 以及参数后进行调试。
+
+## 运行条件
+
+- 下载并解压需要语言的代码;
+
+
+- 在阿里云帐户中获取您的 [凭证](https://usercenter.console.aliyun.com/#/manage/ak)并通过它替换下载后代码中的 ACCESS_KEY_ID 以及 ACCESS_KEY_SECRET;
+
+- 执行对应语言的构建及运行语句
+
+## 执行步骤
+
+下载的代码包,在根据自己需要更改代码中的参数和 AK 以后,可以在**解压代码所在目录下**按如下的步骤执行
+
+- Python
+- *Python 版本要求 Python3*
+```sh
+python3 setup.py install && python ./alibabacloud_sample/sample.py
+```
+## 使用的 API
+
+-  RecognizeAllText OCR统一识别接口支持识别多种图片类型,包括通用文字、个人卡证、发票等。您只需要通过Type参数指定图片类型,无须更换接口。文档示例,可以参考:[文档](https://next.api.aliyun.com/document/ocr-api/2021-07-07/RecognizeAllText)
+
+## 返回示例
+
+*实际输出结构可能稍有不同,属于正常返回;下列输出值仅作为参考,以实际调用为准*
+
+
+*实际输出结构可能稍有不同,属于正常返回;下列输出值仅作为参考,以实际调用为准*
+

+ 9 - 0
alibabacloud_sample.egg-info/SOURCES.txt

@@ -0,0 +1,9 @@
+README.md
+setup.py
+alibabacloud_sample/__init__.py
+alibabacloud_sample/sample.py
+alibabacloud_sample.egg-info/PKG-INFO
+alibabacloud_sample.egg-info/SOURCES.txt
+alibabacloud_sample.egg-info/dependency_links.txt
+alibabacloud_sample.egg-info/requires.txt
+alibabacloud_sample.egg-info/top_level.txt

+ 1 - 0
alibabacloud_sample.egg-info/dependency_links.txt

@@ -0,0 +1 @@
+

+ 5 - 0
alibabacloud_sample.egg-info/requires.txt

@@ -0,0 +1,5 @@
+alibabacloud_ocr-api20210707<3.0.0,>=2.0.8
+alibabacloud_tea_openapi<1.0.0,>=0.3.8
+alibabacloud_tea_console<1.0.0,>=0.0.1
+alibabacloud_tea_util<1.0.0,>=0.3.11
+alibabacloud_darabonba_stream<1.0.0,>=0.0.1

+ 1 - 0
alibabacloud_sample.egg-info/top_level.txt

@@ -0,0 +1 @@
+alibabacloud_sample

+ 1 - 0
alibabacloud_sample/__init__.py

@@ -0,0 +1 @@
+__version__ = "1.0.0"

+ 23 - 0
alibabacloud_sample/file_utils.py

@@ -0,0 +1,23 @@
+from flask import Flask, request
+from werkzeug.utils import secure_filename
+import os
+
+app = Flask(__name__)
+app.config['UPLOAD_FOLDER'] = 'uploads'  # 替换为你的上传文件夹路径
+
+
+@app.route('/upload', methods=['POST'])
+def upload_file():
+    if 'file' not in request.files:
+        return "No file part"
+    file = request.files['file']
+    if file.filename == '':
+        return "No selected file"
+    if file:  # 这里可以加文件类型判断逻辑
+        filename = secure_filename(file.filename)
+        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
+        return "File uploaded successfully"
+
+
+if __name__ == '__main__':
+    app.run(host='0.0.0.0', port=8000, debug=True)

+ 100 - 0
alibabacloud_sample/sample.py

@@ -0,0 +1,100 @@
+# -*- coding: utf-8 -*-
+# This file is auto-generated, don't edit it. Thanks.
+import json
+import os
+import sys
+
+from typing import List
+
+from alibabacloud_ocr_api20210707.client import Client as ocr_api20210707Client
+from alibabacloud_tea_openapi import models as open_api_models
+from alibabacloud_darabonba_stream.client import Client as StreamClient
+from alibabacloud_ocr_api20210707 import models as ocr_api_20210707_models
+from alibabacloud_tea_util import models as util_models
+from alibabacloud_tea_console.client import Client as ConsoleClient
+from alibabacloud_tea_util.client import Client as UtilClient
+
+
+class Sample:
+    def __init__(self):
+        pass
+
+    @staticmethod
+    def create_client() -> ocr_api20210707Client:
+        """
+        使用AK&SK初始化账号Client
+        @return: Client
+        @throws Exception
+        """
+        # 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
+        # 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378659.html。
+        config = open_api_models.Config(
+            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
+            # access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
+            access_key_id='LTAI5tSreWTgmQoCNE8NwKqn',
+            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
+            # access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
+            access_key_secret='re273RJmgwt1Oh8uVZGweSaAggll9o'
+        )
+        # Endpoint 请参考 https://api.aliyun.com/product/ocr-api
+        config.endpoint = f'ocr-api.cn-hangzhou.aliyuncs.com'
+        return ocr_api20210707Client(config)
+
+    @staticmethod
+    def main(
+        args: List[str],
+    ) -> None:
+        client = Sample.create_client()
+        # 需要安装额外的依赖库,直接点击下载完整工程即可看到所有依赖。
+        body_stream = StreamClient.read_from_file_path('uploads/20240301172645.jpg')
+        recognize_all_text_request = ocr_api_20210707_models.RecognizeAllTextRequest(
+            body=body_stream,
+            type='TrainTicket',
+            output_figure=False,
+            output_qrcode=False
+        )
+        runtime = util_models.RuntimeOptions()
+        try:
+            resp = client.recognize_all_text_with_options(recognize_all_text_request, runtime)
+            # ConsoleClient.log(UtilClient.to_jsonstring(resp))
+            data = json.loads(UtilClient.to_jsonstring(resp))
+            if data['statusCode'] == 200:
+                ConsoleClient.log("far:" + data['body']['Data']['SubImages'][0]['KvInfo']['KvDetails']['fare']['Value'])
+                ConsoleClient.log("ticketNumber:" + data['body']['Data']['SubImages'][0]['KvInfo']['Data']['ticketNumber'])
+
+        except Exception as error:
+            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
+            # 错误 message
+            print(error.message)
+            # 诊断地址
+            print(error.data.get("Recommend"))
+            UtilClient.assert_as_string(error.message)
+
+    @staticmethod
+    async def main_async(
+        args: List[str],
+    ) -> None:
+        client = Sample.create_client()
+        # 需要安装额外的依赖库,直接点击下载完整工程即可看到所有依赖。
+        body_stream = StreamClient.read_from_file_path('uploads/20240301172645.jpg')
+        recognize_all_text_request = ocr_api_20210707_models.RecognizeAllTextRequest(
+            body=body_stream,
+            type='TrainTicket',
+            output_figure=False,
+            output_qrcode=False
+        )
+        runtime = util_models.RuntimeOptions()
+        try:
+            resp = await client.recognize_all_text_with_options_async(recognize_all_text_request, runtime)
+            ConsoleClient.log(UtilClient.to_jsonstring(resp))
+        except Exception as error:
+            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
+            # 错误 message
+            print(error.message)
+            # 诊断地址
+            print(error.data.get("Recommend"))
+            UtilClient.assert_as_string(error.message)
+
+
+if __name__ == '__main__':
+    Sample.main(sys.argv[1:])

BIN
alibabacloud_sample/uploads/031002300311_91766124.pdf


BIN
alibabacloud_sample/uploads/031002300311_91820885.pdf


BIN
alibabacloud_sample/uploads/031002300311_92035499.pdf


BIN
alibabacloud_sample/uploads/20240301172645.jpg


BIN
alibabacloud_sample/uploads/20240408__146.jpg


+ 80 - 0
setup.py

@@ -0,0 +1,80 @@
+# -*- coding: utf-8 -*-
+"""
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+"""
+
+import os
+from setuptools import setup, find_packages
+
+"""
+setup module for alibabacloud_sample.
+
+Created on 25/04/2024
+
+@author: 
+"""
+
+PACKAGE = "alibabacloud_sample"
+NAME = "alibabacloud_sample" or "alibabacloud-package"
+DESCRIPTION = "Alibaba Cloud SDK Code Sample Library for Python"
+AUTHOR = ""
+AUTHOR_EMAIL = ""
+URL = "https://github.com/aliyun/alibabacloud-sdk"
+VERSION = __import__(PACKAGE).__version__
+REQUIRES = [
+    "alibabacloud_ocr-api20210707>=2.0.8, <3.0.0",
+    "alibabacloud_tea_openapi>=0.3.8, <1.0.0",
+    "alibabacloud_tea_console>=0.0.1, <1.0.0",
+    "alibabacloud_tea_util>=0.3.11, <1.0.0",
+    "alibabacloud_darabonba_stream>=0.0.1, <1.0.0"
+]
+
+LONG_DESCRIPTION = ''
+if os.path.exists('./README.md'):
+    with open("README.md", encoding='utf-8') as fp:
+        LONG_DESCRIPTION = fp.read()
+
+setup(
+    name=NAME,
+    version=VERSION,
+    description=DESCRIPTION,
+    long_description=LONG_DESCRIPTION,
+    long_description_content_type='text/markdown',
+    author=AUTHOR,
+    author_email=AUTHOR_EMAIL,
+    license="Apache License 2.0",
+    url=URL,
+    keywords=["alibabacloud","sample"],
+    packages=find_packages(exclude=["tests*"]),
+    include_package_data=True,
+    platforms="any",
+    install_requires=REQUIRES,
+    python_requires=">=3.6",
+    classifiers=(
+        "Development Status :: 4 - Beta",
+        "Intended Audience :: Developers",
+        "License :: OSI Approved :: Apache Software License",
+        "Programming Language :: Python",
+        "Programming Language :: Python :: 3",
+        "Programming Language :: Python :: 3.6",
+        'Programming Language :: Python :: 3.7',
+        'Programming Language :: Python :: 3.8',
+        'Programming Language :: Python :: 3.9',
+        "Topic :: Software Development"
+    )
+)