这是一个客户测试.ai分类器RPC服务器,它允许通过pythonapi直接使用分类器,还提供了一个与Selenium一起使用的助手方法。

testai-classifier的Python项目详细描述


在测试.ai分类器-Python客户端

此目录中的代码定义用于gRPC-based Test.ai classifier server的客户端库。在

安装和设置

pip install testai_classifier

使用

此包公开ClassifierClient类:

^{pr2}$

您可以使用它尝试将图像与语义标签匹配:

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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
我可以用C++代码使用java代码吗?   java使用JSR303在派生类中提供更具体的约束   java在这个查找唯一路径数算法中我做错了什么?   java如何为2个不同的服务提供商使用2个不同的SSL证书?   java在Gridview上绘制文本   java使用连接for循环构建字符串名   java StringBuilder拆分无法处理某些文件   java事件关注EditText   Java Web Start“找不到URL的缓存资源”   java程序从命令行运行的速度比在Eclipse中慢   java为什么HttpServletRequest会截断#字符上的url输入?   java自定义折叠工具栏平滑标题大小调整   使用Mockito对安卓 java中调用另一个静态函数的函数进行单元测试   http在java客户机中使用cachecontrol头   java如何使用。是否使用Delimiter从输入文件中排除标点符号和数字?   使用上下文作为参数/参数的java   java更有效地从Jar中提取文件   java为多个JButton提供相同的actionListener