Skip to main content

From CV detection to answer questions

Project description

1. 安装

(1). 方法1:使用pip安装
pip install icare-nlp
Pypi链接: https://pypi.org/project/icare-nlp/
(2). 方法2: 使用Source Codes安装
git clone https://github.com/YiyiyiZhao/icare_nlp_tools.git
cd icare_nlp_tools
pip install -e .
pip install -r requirements.txt

2. 使用

2.0 Task_Disp: 输入User query, 输出对应下列四种的Task类型
(1). Commands
from icare_nlp.task_disp import TaskDisp

task_disp=TaskDisp()
task_disp.disp_start()
(2). Demo

Object Description and QA Receipt Description and QA

2.1 Object_Desc: 输入object detection list, 输出场景播报
import json
from icare_nlp.object_desc import ObjectDesc
obj_desc=ObjectDesc()

with open("./obj_detect_files/59.json", "r") as f:
    obj_detect=json.load(f)
print(obj_detect)
#[{'position': [1149, 580, 258, 270], 'text': 'chair'}, {'position': [958, 186, 235, 171], 'text': 'tv'}, {'position': [1130, 399, 211, 132], 'text': 'chair'}, {'position': [198, 388, 153, 52], 'text': 'chair'}, {'position': [664, 609, 259, 211], 'text': 'chair'}, {'position': [869, 384, 123, 164], 'text': 'chair'}, {'position': [162, 508, 94, 163], 'text': 'bottle'}, {'position': [785, 309, 56, 36], 'text': 'chair'}, {'position': [620, 341, 152, 177], 'text': 'suitcase'}, {'position': [577, 608, 436, 210], 'text': 'chair'}, {'position': [357, 336, 83, 72], 'text': 'chair'}, {'position': [417, 508, 830, 404], 'text': 'dining table'}, {'position': [862, 545, 121, 178], 'text': 'handbag'}, {'position': [862, 545, 122, 177], 'text': 'backpack'}, {'position': [791, 389, 91, 184], 'text': 'chair'}]

obj_desc_res=obj_desc.form_response(obj_detect)
print(obj_desc_res)

#而家眼前嘅景象有9把椅, 1台電視, 1瓶樽, 1個行李箱, 1張飯枱, 1個手袋, 1個書包.視線左上角嘅場景入面有1個行李箱.視線左上角嘅場景入面有1把椅.視線右上角嘅場景入面有1台電視.視線右上角嘅場景入面有1把椅.視線左下角嘅場景入面有2把椅.視線左下角嘅場景入面有1瓶樽.視線左下角嘅場景入面有1張飯枱.視線右下角嘅場景入面有5把椅.視線右下角嘅場景入面有1個手袋.視線右下角嘅場景入面有1個書包.
2.2 Object_QA: 输入object detection list 和 Question, 输出场景有关的Answer
import json
from icare_nlp.object_qa import ObjectQA
obj_qa=ObjectQA()
with open("./obj_detect_files/24.json", "r") as f:
    obj_detect=json.load(f)
print(obj_detect)
#[{'position': [999, 349, 213, 254], 'text': 'chair'}, {'position': [221, 64, 427, 125], 'text': 'tv'}, {'position': [72, 325, 144, 58], 'text': 'chair'}, {'position': [873, 221, 78, 49], 'text': 'chair'}, {'position': [101, 535, 177, 267], 'text': 'cup'}, {'position': [1013, 589, 211, 253], 'text': 'handbag'}, {'position': [663, 289, 242, 324], 'text': 'suitcase'}, {'position': [1231, 535, 96, 303], 'text': 'chair'}]


question="我點樣可以攞到椅子?"
obj_desc_res=obj_qa.form_response(question,obj_detect)
print(obj_desc_res)
#chair喺中心點嘅右上方. 椅子有一個堅硬嘅框架,通常由木頭或金屬製成,座位和背部軟。

question="手袋喺我手嘅邊個方向?"
obj_desc_res=obj_qa.form_response(question,obj_detect)
print(obj_desc_res)
#handbag喺中心點嘅右上方. 手袋嘅大小各異,由軟皮革至硬合成材料製成。

question="椅子附近有冇其他物體?"
obj_desc_res=obj_qa.form_response(question,obj_detect)
print(obj_desc_res)
#chair最近嘅物件系 chair,handbag,chair.chair喺chair嘅左上方.handbag喺chair嘅右下方.chair喺chair嘅右下方.. 椅子有一個堅硬嘅框架,通常由木頭或金屬製成,座位和背部軟。
2.3 Receipt_Desc: 输入Receipt的OCR识别文本, 输出Receipt描述
import json
from icare_nlp.receipt_desc import ReceiptDesc
receipt_desc=ReceiptDesc()


with open("./ocr_detect_files/ocr_azure.json", "r") as f:
        ocr_data = json.load(f)
ocr_text = ""
for item in ocr_data:
    ocr_text += item["text"] + '\n'


rec_desc_res=receipt_desc.form_response(ocr_text)
print(rec_desc_res)
#呢张收据主要嘅信息包括外賣, 點餐時間, 收據號碼, 新加坡海南雞, 點餐號碼, 優惠碼, 当久於, 腸仔猪扒雞扒飯, 秘製燒汁, 白飯, 少鹽, 概沟, 小計, 折扣, 總金額, 付款資料, 付款方式, 扣除金額, 餘額, 卡號, 機號, 發票號碼, 交易時間, 绿联, 深圳市绿联科技股份有限公司, 地址深圳市龙华区龙观西路龙城工业区绿联办公大楼, 电话, 官网, 执行标准
2.4 Receipt_QA: 输入Receipt的OCR识别文本, 输出票据总价
#!/bin/bash
export OPEN_API_KEY="your_api_key_here"
import json
from icare_nlp.receipt_qa import ReceiptQA
receipt_qa=ReceiptQA()


with open("./ocr_detect_files/ocr_azure.json", "r") as f:
        ocr_data = json.load(f)
ocr_text = ""
for item in ocr_data:
    ocr_text += item["text"] + '\n'


rec_desc_res=receipt_qa.form_response(ocr_text)
print(rec_desc_res)
#總花費係: 51.0.

3. Structure and Other Information

The core structure is:

├── __init__.py
├── object_desc.py
├── object_qa.py
├── receipt_desc.py
├── receipt_qa.py
├── resources
├── task_disp.py
└── utils.py

There are some files for you to have a try: If you want to try the object description and question answering functions:

./examples/obj_detect_files

If you want to try the receipt description and question answering functions:

./examples/ocr_detect_files

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

icare_nlp-0.0.5.tar.gz (252.8 kB view details)

Uploaded Source

Built Distribution

icare_nlp-0.0.5-py3-none-any.whl (255.3 kB view details)

Uploaded Python 3

File details

Details for the file icare_nlp-0.0.5.tar.gz.

File metadata

  • Download URL: icare_nlp-0.0.5.tar.gz
  • Upload date:
  • Size: 252.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for icare_nlp-0.0.5.tar.gz
Algorithm Hash digest
SHA256 db04503fb7eb7b386b1e583c9986407817990ca11ec93a4da8f2a71a9091b5bd
MD5 b1b4ccfdd3adcf6df819fdeda1f81fc0
BLAKE2b-256 5afc0dfd46d06720dd1df8e4296fb19a506f36aec5bf75d023af026b8807d732

See more details on using hashes here.

File details

Details for the file icare_nlp-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: icare_nlp-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 255.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for icare_nlp-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fc359848c22b20c02a58e10a507b90eb621a9f393647f3ac12f7372f3d0f0a90
MD5 ba0f582f0a1fa22397aae08f4c8fdbe8
BLAKE2b-256 1eb90d19f02cb883898366914b58abfd5cfc49f2fab641783672bca31312330a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page