这是一个客户测试.ai分类器RPC服务器,它允许通过pythonapi直接使用分类器,还提供了一个与Selenium一起使用的助手方法。
testai-classifier的Python项目详细描述
在测试.ai分类器-Python客户端
此目录中的代码定义用于gRPC-based Test.ai classifier server的客户端库。在
安装和设置
pip install testai_classifier
使用
此包公开ClassifierClient
类:
您可以使用它尝试将图像与语义标签匹配:
defclassify():client=ClassifierClient(HOST,PORT)# assume cart_img and menu_img are byte streams as delivered by file.read()# define a mapping between ids and image datadata={'cart':cart_img,'menu':menu_img}# define which label we are looking to matchlabel='cart'# attempt to match the images with the label# confidence is from 0.0 to 1.0 -- any matches with lower than the specified# confidence are not returned.# allow_weaker_matches specifies whether to return matches that are above# the confidence threshold but whose most confident match was a *different*# labelres=client.classify_images(label,data,confidence=0.0,allow_weaker_matches=True)# res looks like:# {'cart': {'label': 'cart', 'confidence': 0.9, 'confidence_for_hint': 0.9},# 'menu': {'label': 'menu', 'confidence': 0.9, 'confidence_for_hint': 0.2}}# always close the client connectionclient.close()
您还可以将其与Selenium Python客户端驱动程序对象结合使用,以根据标签在网页中查找元素:
deffind_elements():client=ClassifierClient(HOST,PORT)driver.get("https://test.ai")els=client.find_elements_matching_label(driver,"twitter")els[0].click()assertdriver.current_url=="https://twitter.com/testdotai"client.close()
发展
make install
-安装deps(需要Pipenv)make protogen
-从.proto文件生成python客户端帮助程序make clean
-重置生成的文件make build
-运行设置.py生成可发布文件make test
-运行测试套件(同时make unit-test
和{}) make publish
-发布到pypi(也make publish-test
)
- 项目
标签: