图片信息抽取

图片信息抽取服务提供智能信息抽取能力,可从合同、票据与表单中自动识别并提取金额、日期、主体等关键字段,支持自定义字段配置,提升数据处理效率与准确性。

​根据图片提取信息

根据详尽的文本描述(prompt),提取指定JSON格式的结构化信息。

Python
import requests
import os
import mimetypes

url = "https://maas-api.uat.hivoice.cn/v1/ocr/image/extract"
api_key = os.environ.get("API_KEY")
headers = {"Authorization": f"Bearer {api_key}"}

IMAGE_PATH = "invoice.png"
PROMPT = """请提取图片中的信息,严格按 JSON 格式输出。
Schema 如下:
{
  "invoice_no": "发票号码",
  "date": "开票日期",
  "items": [{"name": "项目名称", "total": "金额"}]
}"""

payload = {
    "model": "u1-ocr-extract",
    "prompt": PROMPT
}

with open(IMAGE_PATH, "rb") as image_file:
    files = {
        "image": (
            os.path.basename(IMAGE_PATH),
            image_file,
            mimetypes.guess_type(IMAGE_PATH)[0]
        )
    }
    response = requests.post(url, headers=headers, data=payload, files=files)

result = response.json()
print(f"{result['content']}")

应用示例

输入

发票示例图片

prompt


请提取图片中的信息,严格按 JSON 格式输出。
Schema 如下:
{
  "invoice_no": "发票号码",
  "date": "开票日期",
  "items": [
    {"name": "项目名称", 
    "total": "金额"
  }]
}

输出


{
    "invoice_no": "25117000001021449288",
    "date": "2025年08月07日",
    "items": [{
        "name": "*运输服务*客运服务费",
        "total": "109.13"
    }]
}