Просмотр исходного кода

fix python code (#3448)

* fix python code

* update
zhang-prog 8 месяцев назад
Родитель
Сommit
40e31a7af0

+ 10 - 10
docs/pipeline_usage/tutorials/information_extraction_pipelines/document_scene_information_extraction_v4.en.md

@@ -1853,24 +1853,26 @@ Below are the API references for basic serving and multi-language service invoca
 <details>
 <summary>Python</summary>
 
-<pre><code class="language-python">import base64
+<pre><code class="language-python">
+# This script only shows the use case for images. For calling with other file types, please read the API reference and make adjustments.
+
+import base64
 import pprint
 import sys
-
 import requests
 
 
 API_BASE_URL = "http://0.0.0.0:8080"
 
-file_path = "./demo.jpg"
+image_path = "./demo.jpg"
 keys = ["name"]
 
-with open(file_path, "rb") as file:
-    file_bytes = file.read()
-    file_data = base64.b64encode(file_bytes).decode("ascii")
+with open(image_path, "rb") as file:
+    image_bytes = file.read()
+    image_data = base64.b64encode(image_bytes).decode("ascii")
 
 payload = {
-    "file": file_data,
+    "file": image_data,
     "fileType": 1,
 }
 
@@ -1904,7 +1906,7 @@ if resp_vector.status_code != 200:
 result_vector = resp_vector.json()["result"]
 
 payload = {
-    "image": image_url,
+    "image": image_data,
     "keyList": keys,
 }
 resp_mllm = requests.post(url=f"{API_BASE_URL}/chatocr-mllm", json=payload)
@@ -1934,8 +1936,6 @@ result_chat = resp_chat.json()["result"]
 print("Final result:")
 print(result_chat["chatResult"])
 </code></pre>
-
-<b>Note</b>: Please fill in your API key and secret key in `API_KEY` and `SECRET_KEY`.
 </details>
 </details>
 <br/>

+ 11 - 11
docs/pipeline_usage/tutorials/information_extraction_pipelines/document_scene_information_extraction_v4.md

@@ -2018,24 +2018,26 @@ for res in visual_predict_res:
 <summary>Python</summary>
 
 
-<pre><code class="language-python">import base64
+<pre><code class="language-python">
+# 此脚本只展示了图片的用例,其他文件类型的调用请查看API参考来调整
+
+import base64
 import pprint
 import sys
-
 import requests
 
 
 API_BASE_URL = "http://0.0.0.0:8080"
 
-file_path = "./demo.jpg"
+image_path = "./demo.jpg"
 keys = ["姓名"]
 
-with open(file_path, "rb") as file:
-    file_bytes = file.read()
-    file_data = base64.b64encode(file_bytes).decode("ascii")
+with open(image_path, "rb") as file:
+    image_bytes = file.read()
+    image_data = base64.b64encode(image_bytes).decode("ascii")
 
 payload = {
-    "file": file_data,
+    "file": image_data,
     "fileType": 1,
 }
 
@@ -2069,7 +2071,7 @@ if resp_vector.status_code != 200:
 result_vector = resp_vector.json()["result"]
 
 payload = {
-    "image": image_url,
+    "image": image_data,
     "keyList": keys,
 }
 resp_mllm = requests.post(url=f"{API_BASE_URL}/chatocr-mllm", json=payload)
@@ -2099,9 +2101,7 @@ result_chat = resp_chat.json()["result"]
 print("Final result:")
 print(result_chat["chatResult"])
 </code></pre>
-
-
-<b>注</b>:请在 `API_KEY`、`SECRET_KEY` 处填入您的 API key 和 secret key。</details>
+</details>
 </details>
 <br/>