Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PP-ChatOCRv3-doc 提取时出现错误 #2786

Open
chenzhen1120 opened this issue Jan 7, 2025 · 7 comments
Open

PP-ChatOCRv3-doc 提取时出现错误 #2786

chenzhen1120 opened this issue Jan 7, 2025 · 7 comments
Assignees

Comments

@chenzhen1120
Copy link

服务错误信息:
INFO: 127.0.0.1:16503 - "POST /chatocr-retrieval HTTP/1.1" 200 OK
1 validation error for Prompts
ocr
Input should be a valid string [type=string_type, input_value=['你现在的任务是...:[['甲方']]。'], input_type=list]
For further information visit https://errors.pydantic.dev/2.9/v/string_type
Traceback (most recent call last):
File "C:\TechStack\OpenSourceHub\anaconda\envs\PaddleX-GPU\lib\site-packages\paddlex\inference\pipelines\serving_pipeline_apps\ppchatocrv3.py", line 422, in _chat
prompts = Prompts(
File "C:\TechStack\OpenSourceHub\anaconda\envs\PaddleX-GPU\lib\site-packages\pydantic\main.py", line 212, in init
validated_self = self.pydantic_validator.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Prompts
ocr
Input should be a valid string [type=string_type, input_value=['你现在的任务是...:[['甲方']]。'], input_type=list]
For further information visit https://errors.pydantic.dev/2.9/v/string_type
INFO: 127.0.0.1:16505 - "POST /chatocr-chat HTTP/1.1" 500 Internal Server Error

调用源码:
import base64
import pprint
import sys

import requests

API_BASE_URL = "http://127.0.0.1:8080"
API_KEY = "lUh2I5ebh8FMSh7ClZWN8921"
SECRET_KEY = "BnigOPMlSqH7uWEhxJlgT9i0XDF3oSaE"
ACCESS_TOKEN = "bbcd770c397622aa7028aa8d74f25d7f1ccadd4c"
LLM_NAME = "ernie-3.5"
LLM_PARAMS = {
"apiType": "qianfan",
"apiKey": API_KEY,
"secretKey": SECRET_KEY,
#"accessToken": ACCESS_TOKEN,
}

file_path = "./contract.jpg"
keys = ["甲方"]

with open(file_path, "rb") as file:
file_bytes = file.read()
file_data = base64.b64encode(file_bytes).decode("ascii")

payload = {
"file": file_data,
"fileType": 1,
"useImgOrientationCls": True,
"useImgUnwrapping": True,
"useSealTextDet": True,
}
resp_vision = requests.post(url=f"{API_BASE_URL}/chatocr-vision", json=payload)
if resp_vision.status_code != 200:
print(
f"Request to chatocr-vision failed with status code {resp_vision.status_code}."
)
pprint.pp(resp_vision.json())
sys.exit(1)
result_vision = resp_vision.json()["result"]

for i, res in enumerate(result_vision["visionResults"]):
pprint.pp(res["texts"])
pprint.pp(res["tables"])
ocr_img_path = f"ocr_{i}.jpg"
with open(ocr_img_path, "wb") as f:
f.write(base64.b64decode(res["ocrImage"]))
layout_img_path = f"layout_{i}.jpg"
with open(layout_img_path, "wb") as f:
f.write(base64.b64decode(res["layoutImage"]))
print(f"Output images saved at {ocr_img_path} and {layout_img_path}")
print("=============OCR完成=============")

payload = {
"visionInfo": result_vision["visionInfo"],
"minChars": 200,
"llmRequestInterval": 1000,
"llmName": LLM_NAME,
"llmParams": LLM_PARAMS,
}
resp_vector = requests.post(url=f"{API_BASE_URL}/chatocr-vector", json=payload)
if resp_vector.status_code != 200:
print(
f"Request to chatocr-vector failed with status code {resp_vector.status_code}."
)
pprint.pp(resp_vector.json())
sys.exit(1)
result_vector = resp_vector.json()["result"]
print("=============构建向量库完成=============")

payload = {
"keys": keys,
"vectorStore": result_vector["vectorStore"],
"llmName": LLM_NAME,
"llmParams": LLM_PARAMS,
}
resp_retrieval = requests.post(url=f"{API_BASE_URL}/chatocr-retrieval", json=payload)
if resp_retrieval.status_code != 200:
print(
f"Request to chatocr-retrieval failed with status code {resp_retrieval.status_code}."
)
pprint.pp(resp_retrieval.json())
sys.exit(1)
result_retrieval = resp_retrieval.json()["result"]

print("=============================")

payload = {
"keys": keys,
"visionInfo": result_vision["visionInfo"],
"vectorStore": result_vector["vectorStore"],
"retrievalResult": result_retrieval["retrievalResult"],
"taskDescription": "",
"rules": "",
"fewShot": "",
"llmName": LLM_NAME,
"llmParams": LLM_PARAMS,
"returnPrompts": True,
}
resp_chat = requests.post(url=f"{API_BASE_URL}/chatocr-chat", json=payload)
if resp_chat.status_code != 200:
print(
f"Request to chatocr-chat failed with status code {resp_chat.status_code}."
)
pprint.pp(resp_chat.json())
sys.exit(1)
result_chat = resp_chat.json()["result"]
print("\nPrompts:")
pprint.pp(result_chat["prompts"])
print("Final result:")
print(result_chat["chatResult"])

@cuicheng01
Copy link
Collaborator

服务化部署报错还是?

@chenzhen1120
Copy link
Author

服务化部署报错还是?

服务化部署报错

@Bobholamovic
Copy link
Member

请问你用的是什么版本的paddlex呀?

@chenzhen1120
Copy link
Author

chenzhen1120 commented Jan 9, 2025

请问你用的是什么版本的paddlex呀?

环境:
paddlepaddle-gpu==3.0.0b2 paddlepaddle-cuda=11.8
paddlex-3.0.0b2-py3-none-any.whl
paddlex用的是阿里云的镜像

@Bobholamovic
Copy link
Member

请用develop版本的paddlex试试~

@chenzhen1120
Copy link
Author

请用develop版本的paddlex试试~

好的... develop版本只能插件安装吗

@Bobholamovic
Copy link
Member

不需要安装服务化部署插件以外的插件,只要拉取源码,安装PaddleX后再安装服务化部署插件即可

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants