icare-nlp


Nameicare-nlp JSON
Version 0.0.8 PyPI version JSON
download
home_pageNone
SummaryFrom CV detection to answer questions
upload_time2024-05-16 08:51:56
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseNone
keywords icare language
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            #### 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. 使用
##### Quick Start
~~~
cd ./examples
python run.py
~~~
##### 2.0 Task_Disp: 输入User query, 输出对应下列四种的Task类型
###### (1). Commands
~~~
from icare_nlp.task_disp import TaskDisp

task_disp=TaskDisp()
task_disp.disp_start()
~~~
~~~
#Intent classification
task_disp=TaskDisp()
user_query="可以確認下有冇糖不甩?"
task_disp.intent_classify(user_query)
#SYSTEM: 我會幫你完成呢個收據問答嘅任務。
~~~
###### (2). Demo
***Object Description and QA***
![](./examples/figs/object_desc_qa_0513.gif)
***Receipt Description and QA***
![](./examples/figs/receipt_desc_qa_0513.gif)
##### 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识别文本 和 Question, 输出Answer [GPT-3.5 assisted]
~~~
#!/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'

question="我總共花咗幾多錢?"
rec_desc_res=receipt_qa.form_response(ocr_text, question)
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
~~~

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "icare-nlp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "icare, language",
    "author": null,
    "author_email": "23037086r@connect.polyu.hk",
    "download_url": null,
    "platform": null,
    "description": "#### 1. \u5b89\u88c5\n##### (1). \u65b9\u6cd51\uff1a\u4f7f\u7528pip\u5b89\u88c5\n~~~\npip install icare-nlp\nPypi\u94fe\u63a5: https://pypi.org/project/icare-nlp/\n~~~\n##### (2). \u65b9\u6cd52\uff1a \u4f7f\u7528Source Codes\u5b89\u88c5\n~~~\ngit clone https://github.com/YiyiyiZhao/icare_nlp_tools.git\ncd icare_nlp_tools\npip install -e .\npip install -r requirements.txt\n~~~\n\n#### 2. \u4f7f\u7528\n##### Quick Start\n~~~\ncd ./examples\npython run.py\n~~~\n##### 2.0 Task_Disp: \u8f93\u5165User query, \u8f93\u51fa\u5bf9\u5e94\u4e0b\u5217\u56db\u79cd\u7684Task\u7c7b\u578b\n###### (1). Commands\n~~~\nfrom icare_nlp.task_disp import TaskDisp\n\ntask_disp=TaskDisp()\ntask_disp.disp_start()\n~~~\n~~~\n#Intent classification\ntask_disp=TaskDisp()\nuser_query=\"\u53ef\u4ee5\u78ba\u8a8d\u4e0b\u6709\u5187\u7cd6\u4e0d\u7529\uff1f\"\ntask_disp.intent_classify(user_query)\n#SYSTEM\uff1a \u6211\u6703\u5e6b\u4f60\u5b8c\u6210\u5462\u500b\u6536\u64da\u554f\u7b54\u5605\u4efb\u52d9\u3002\n~~~\n###### (2). Demo\n***Object Description and QA***\n![](./examples/figs/object_desc_qa_0513.gif)\n***Receipt Description and QA***\n![](./examples/figs/receipt_desc_qa_0513.gif)\n##### 2.1 Object_Desc: \u8f93\u5165object detection list, \u8f93\u51fa\u573a\u666f\u64ad\u62a5\n~~~\nimport json\nfrom icare_nlp.object_desc import ObjectDesc\nobj_desc=ObjectDesc()\n\nwith open(\"./obj_detect_files/59.json\", \"r\") as f:\n    obj_detect=json.load(f)\nprint(obj_detect)\n#[{'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'}]\n\nobj_desc_res=obj_desc.form_response(obj_detect)\nprint(obj_desc_res)\n\n#\u800c\u5bb6\u773c\u524d\u5605\u666f\u8c61\u67099\u628a\u6905, 1\u53f0\u96fb\u8996, 1\u74f6\u6a3d, 1\u500b\u884c\u674e\u7bb1, 1\u5f35\u98ef\u67b1, 1\u500b\u624b\u888b, 1\u500b\u66f8\u5305.\u8996\u7dda\u5de6\u4e0a\u89d2\u5605\u5834\u666f\u5165\u9762\u67091\u500b\u884c\u674e\u7bb1.\u8996\u7dda\u5de6\u4e0a\u89d2\u5605\u5834\u666f\u5165\u9762\u67091\u628a\u6905.\u8996\u7dda\u53f3\u4e0a\u89d2\u5605\u5834\u666f\u5165\u9762\u67091\u53f0\u96fb\u8996.\u8996\u7dda\u53f3\u4e0a\u89d2\u5605\u5834\u666f\u5165\u9762\u67091\u628a\u6905.\u8996\u7dda\u5de6\u4e0b\u89d2\u5605\u5834\u666f\u5165\u9762\u67092\u628a\u6905.\u8996\u7dda\u5de6\u4e0b\u89d2\u5605\u5834\u666f\u5165\u9762\u67091\u74f6\u6a3d.\u8996\u7dda\u5de6\u4e0b\u89d2\u5605\u5834\u666f\u5165\u9762\u67091\u5f35\u98ef\u67b1.\u8996\u7dda\u53f3\u4e0b\u89d2\u5605\u5834\u666f\u5165\u9762\u67095\u628a\u6905.\u8996\u7dda\u53f3\u4e0b\u89d2\u5605\u5834\u666f\u5165\u9762\u67091\u500b\u624b\u888b.\u8996\u7dda\u53f3\u4e0b\u89d2\u5605\u5834\u666f\u5165\u9762\u67091\u500b\u66f8\u5305.\n~~~\n\n##### 2.2 Object_QA: \u8f93\u5165object detection list \u548c Question, \u8f93\u51fa\u573a\u666f\u6709\u5173\u7684Answer\n~~~\nimport json\nfrom icare_nlp.object_qa import ObjectQA\nobj_qa=ObjectQA()\nwith open(\"./obj_detect_files/24.json\", \"r\") as f:\n    obj_detect=json.load(f)\nprint(obj_detect)\n#[{'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'}]\n\n\nquestion=\"\u6211\u9ede\u6a23\u53ef\u4ee5\u651e\u5230\u6905\u5b50\uff1f\"\nobj_desc_res=obj_qa.form_response(question,obj_detect)\nprint(obj_desc_res)\n#chair\u55ba\u4e2d\u5fc3\u9ede\u5605\u53f3\u4e0a\u65b9. \u6905\u5b50\u6709\u4e00\u500b\u5805\u786c\u5605\u6846\u67b6\uff0c\u901a\u5e38\u7531\u6728\u982d\u6216\u91d1\u5c6c\u88fd\u6210\uff0c\u5ea7\u4f4d\u548c\u80cc\u90e8\u8edf\u3002\n\nquestion=\"\u624b\u888b\u55ba\u6211\u624b\u5605\u908a\u500b\u65b9\u5411\uff1f\"\nobj_desc_res=obj_qa.form_response(question,obj_detect)\nprint(obj_desc_res)\n#handbag\u55ba\u4e2d\u5fc3\u9ede\u5605\u53f3\u4e0a\u65b9. \u624b\u888b\u5605\u5927\u5c0f\u5404\u7570\uff0c\u7531\u8edf\u76ae\u9769\u81f3\u786c\u5408\u6210\u6750\u6599\u88fd\u6210\u3002\n\nquestion=\"\u6905\u5b50\u9644\u8fd1\u6709\u5187\u5176\u4ed6\u7269\u9ad4\uff1f\"\nobj_desc_res=obj_qa.form_response(question,obj_detect)\nprint(obj_desc_res)\n#chair\u6700\u8fd1\u5605\u7269\u4ef6\u7cfb chair,handbag,chair.chair\u55bachair\u5605\u5de6\u4e0a\u65b9.handbag\u55bachair\u5605\u53f3\u4e0b\u65b9.chair\u55bachair\u5605\u53f3\u4e0b\u65b9.. \u6905\u5b50\u6709\u4e00\u500b\u5805\u786c\u5605\u6846\u67b6\uff0c\u901a\u5e38\u7531\u6728\u982d\u6216\u91d1\u5c6c\u88fd\u6210\uff0c\u5ea7\u4f4d\u548c\u80cc\u90e8\u8edf\u3002\n~~~\n\n##### 2.3 Receipt_Desc: \u8f93\u5165Receipt\u7684OCR\u8bc6\u522b\u6587\u672c, \u8f93\u51faReceipt\u63cf\u8ff0\n~~~\nimport json\nfrom icare_nlp.receipt_desc import ReceiptDesc\nreceipt_desc=ReceiptDesc()\n\n\nwith open(\"./ocr_detect_files/ocr_azure.json\", \"r\") as f:\n        ocr_data = json.load(f)\nocr_text = \"\"\nfor item in ocr_data:\n    ocr_text += item[\"text\"] + '\\n'\n\n\nrec_desc_res=receipt_desc.form_response(ocr_text)\nprint(rec_desc_res)\n#\u5462\u5f20\u6536\u636e\u4e3b\u8981\u5605\u4fe1\u606f\u5305\u62ec\u5916\u8ce3, \u9ede\u9910\u6642\u9593, \u6536\u64da\u865f\u78bc, \u65b0\u52a0\u5761\u6d77\u5357\u96de, \u9ede\u9910\u865f\u78bc, \u512a\u60e0\u78bc, \u5f53\u4e45\u65bc, \u8178\u4ed4\u732a\u6252\u96de\u6252\u98ef, \u79d8\u88fd\u71d2\u6c41, \u767d\u98ef, \u5c11\u9e7d, \u6982\u6c9f, \u5c0f\u8a08, \u6298\u6263, \u7e3d\u91d1\u984d, \u4ed8\u6b3e\u8cc7\u6599, \u4ed8\u6b3e\u65b9\u5f0f, \u6263\u9664\u91d1\u984d, \u9918\u984d, \u5361\u865f, \u6a5f\u865f, \u767c\u7968\u865f\u78bc, \u4ea4\u6613\u6642\u9593, \u7eff\u8054, \u6df1\u5733\u5e02\u7eff\u8054\u79d1\u6280\u80a1\u4efd\u6709\u9650\u516c\u53f8, \u5730\u5740\u6df1\u5733\u5e02\u9f99\u534e\u533a\u9f99\u89c2\u897f\u8def\u9f99\u57ce\u5de5\u4e1a\u533a\u7eff\u8054\u529e\u516c\u5927\u697c, \u7535\u8bdd, \u5b98\u7f51, \u6267\u884c\u6807\u51c6\n~~~\n\n##### 2.4 Receipt_QA: \u8f93\u5165Receipt\u7684OCR\u8bc6\u522b\u6587\u672c \u548c Question, \u8f93\u51faAnswer [GPT-3.5 assisted]\n~~~\n#!/bin/bash\nexport OPEN_API_KEY=\"your_api_key_here\"\n~~~\n~~~\nimport json\nfrom icare_nlp.receipt_qa import ReceiptQA\nreceipt_qa=ReceiptQA()\n\n\nwith open(\"./ocr_detect_files/ocr_azure.json\", \"r\") as f:\n        ocr_data = json.load(f)\nocr_text = \"\"\nfor item in ocr_data:\n    ocr_text += item[\"text\"] + '\\n'\n\nquestion=\"\u6211\u7e3d\u5171\u82b1\u5497\u5e7e\u591a\u9322\uff1f\"\nrec_desc_res=receipt_qa.form_response(ocr_text, question)\nprint(rec_desc_res)\n#51.0.\n~~~\n#### 3. Structure and Other Information\nThe core structure is: \n~~~\n\u251c\u2500\u2500 __init__.py\n\u251c\u2500\u2500 object_desc.py\n\u251c\u2500\u2500 object_qa.py\n\u251c\u2500\u2500 receipt_desc.py\n\u251c\u2500\u2500 receipt_qa.py\n\u251c\u2500\u2500 resources\n\u251c\u2500\u2500 task_disp.py\n\u2514\u2500\u2500 utils.py\n~~~\nThere are some files for you to have a try:\nIf you want to try the object description and question answering functions:\n~~~\n./examples/obj_detect_files\n~~~\nIf you want to try the receipt description and question answering functions:\n~~~\n./examples/ocr_detect_files\n~~~\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "From CV detection to answer questions",
    "version": "0.0.8",
    "project_urls": null,
    "split_keywords": [
        "icare",
        " language"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba6cbf9abc83ea4408c3a81abb3facb5ceec9b18f9b6a39b151a270adb5c3310",
                "md5": "8b3225dafc4c4d2eeb41c7845fd0f690",
                "sha256": "44762d9f5c4e6f2f4b284c232de7cbf7047e5baaabfe9028b6528ce9382912ea"
            },
            "downloads": -1,
            "filename": "icare_nlp-0.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8b3225dafc4c4d2eeb41c7845fd0f690",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10130973,
            "upload_time": "2024-05-16T08:51:56",
            "upload_time_iso_8601": "2024-05-16T08:51:56.000563Z",
            "url": "https://files.pythonhosted.org/packages/ba/6c/bf9abc83ea4408c3a81abb3facb5ceec9b18f9b6a39b151a270adb5c3310/icare_nlp-0.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-16 08:51:56",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "icare-nlp"
}
        
Elapsed time: 0.28426s