【发布时间】:2022-01-21 17:54:20
【问题描述】:
我目前在 Loop 模型中使用自定义 GCP Human,当在本地运行时,它返回的文本似乎是 JSON 文件的形式,但有一些特性使其并非如此。谁能告诉我这个文件是什么? 目前用于生成此代码的代码如下:
def inline_text_payload(file_path):
with open(file_path, 'rb') as ff:
content = ff.read()
return {'text_snippet': {'content': content, 'mime_type': 'text/plain'} }
def pdf_payload(file_path):
return {'document': {'input_config': {'gcs_source': {'input_uris': [file_path] } } } }
def get_prediction(file_path, model_name):
options = ClientOptions(api_endpoint='automl.googleapis.com')
prediction_client = automl_v1.PredictionServiceClient(client_options=options)
#payload = inline_text_payload(file_path)
# Uncomment the following line (and comment the above line) if want to predict on PDFs.
payload = pdf_payload(file_path)
params = {}
request = prediction_client.predict(name=model_name, payload=payload)
return request # waits until request is returned
请求返回如下所示的文本。
payload {
annotation_spec_id: "xxxxx"
display_name: "xxxx"
text_extraction {
score: xxxx
text_segment {
start_offset: xxx
end_offset: xxx
content: "xxxxxx"
}
}
}
payload {
annotation_spec_id: "xxxxx"
display_name: "xxxxx"
text_extraction {
score: xxxx
text_segment {
start_offset: xxxx
end_offset: xxxx
content: "xxxxx"
}
}
}
payload {
annotation_spec_id: "xxxxx"
display_name: "xxxxx"
text_extraction {
score: xxxxx
text_segment {
start_offset: xxxx
end_offset: xxx
content: "xxx"
}
}
}
payload {
annotation_spec_id: "xxxx"
display_name: "xxxxx"
text_extraction {
score: xxxx
text_segment {
start_offset: xxxx
end_offset: xxx
content: "xxxxx"
}
}
}
【问题讨论】:
-
显示生成 JSON 的代码。如所写,您的问题不完整。 stackoverflow.com/help/how-to-ask
-
我已经更改了它,但它不会提供太多帮助,因为大部分代码都在我无法访问的谷歌 API 中
-
这是protobuf文本格式,见重复问题。
标签: file machine-learning google-cloud-platform types