Skip to main content

AIFashion python sdk

AF Open API

本项目是AIFashion® HTTP API的一个封装,旨在为开发者提供简洁高效的SDK。 该SDK可以自动完成身份认证、访问令牌获取、令牌自动更新,并提供各个功能的接口。

ID 与 Secret

您需要首先访问AIFashion®的控制面板,注册并登陆, 创建一个合适的应用并获取应用的ID和Secret

安装

您可以通过pip指令完成安装

pip install aifashion_sdk

使用

通过python调用aifashion包,给定 ID 和 Scret 即可使用

import aifashion

client_id = 'XXXXX'
client_secret = 'YYYYY'
af = aifashion.AIFashionFunctions(client_id=client_id, client_secret=client_secret)

或者您可以保存在yaml文件中,并通过client_filename参数传递文件名

client_id: XXXXX
client_secret: YYYYY
import aifashion

client_filename = 'ZZZZ.yml'
af = aifashion.AIFashionFunctions(client_filename=client_filename)

接下来您可以调用相应的函数获取识别的结果

# if image_url is given
image_url = 'some url here'
af.a_function(image_url=image_url)

# if image_filename is given
image_filename = 'some filename here'
af.a_function(image_fname=image_filename)

# if image_base64 string is given
image_base64 = 'some base64 here'
af.a_function(image_base64=image_base64)

例如:

>>> af.fahsion_tagging(image_url='https://images.aifashion.com/01/0f/c7/010fc7622b1b75f7d580137636f25d88.jpg')
{'image': {'height': 640, 'id': '010fc7622b1b75f7d580137636f25d88', 'url': 'https://images.aifashion.com/01/0f/c7/010fc7622b1b75f7d580137636f25d88.jpg', 'width': 640}, 'object': {'category': '箱包', 'category_id': 501, 'confidence': 0.9646803140640259, 'region': {'x1': 0.07128814697265624, 'x2': 0.9111869812011719, 'y1': 0.041831283569335936, 'y2': 0.9469302368164062}}, 'request_id': '855be4d7-7896-4428-bcf1-507a89a835c5#359895', 'tags': [{'key': '风格', 'values': [{'confidence': 0.26829038772796976, 'value': '韩版'}]}, {'key': '款式', 'values': [{'confidence': 0.7964576377930703, 'value': '单肩包'}]}, {'key': '大小', 'values': [{'confidence': 0.5306223626645841, 'value': '小'}]}, {'key': '图案', 'values': [{'confidence': 0.44190941484801455, 'value': '纯色'}]}, {'key': '适用场景', 'values': [{'confidence': 0.959326524265762, 'value': '休闲'}]}, {'key': '闭合方式', 'values': [{'confidence': 0.6383202888420646, 'value': '拉链'}]}, {'key': '形状', 'values': [{'confidence': 0.44122126961424496, 'value': '横款方形'}]}, {'key': '性别', 'values': [{'confidence': 1.0, 'value': '通用'}]}, {'key': '二级类别', 'values': [{'confidence': 0.81, 'value': '挎包'}]}]}

>>> af.color_analysis(image_fname="dress.jpeg")
{'colors': [{'name_en': 'AntiqueWhite', 'name_zh': '浅橙色', 'percentage': 0.1646513949747629, 'rgb': '#F6EBDD'}, {'name_en': 'DimGray', 'name_zh': '黑灰色', 'percentage': 0.388586906280622, 'rgb': '#5B575A'}, {'name_en': 'Salmon', 'name_zh': '西瓜红', 'percentage': 0.16732301662136928, 'rgb': '#E8696D'}, {'name_en': 'DarkSalmon', 'name_zh': '西瓜红', 'percentage': 0.23548634607206909, 'rgb': '#EF9E97'}, {'name_en': 'SaddleBrown', 'name_zh': '深棕色', 'percentage': 0.04395233605117681, 'rgb': '#5B231C'}], 'image': {'height': 640, 'id': '010fc7622b1b75f7d580137636f25d88', 'url': 'https://images.aifashion.com/01/0f/c7/010fc7622b1b75f7d580137636f25d88.jpg', 'width': 640}, 'object': {'category': '短裙', 'category_id': 301, 'confidence': 0.8859304785728455, 'region': {'x1': 0.06238516420125961, 'x2': 0.9350795149803162, 'y1': 0.019997864961624146, 'y2': 0.9653385281562805}}, 'request_id': '855be4d7-7896-4428-bcf1-507a89a835c5#359896'}

>>> af.clothes_detect(image_fname="red_dress.jpeg")
{'image': {'height': 541, 'id': '2755c68dfc1b44301219bc9f399b3148', 'url': 'https://images.aifashion.com/27/55/c6/2755c68dfc1b44301219bc9f399b3148.jpg', 'width': 500}, 'objects': [{'category': '连衣裙', 'category_id': 302, 'confidence': 0.9999842643737793, 'region': {'x1': 0.15614866256713866, 'x2': 0.8775624847412109, 'y1': 0.22497901348686994, 'y2': 0.9921972458030277}}], 'request_id': '5ec403e2-d5f1-4dc3-aa51-0109c6e43b56#363567'}

AIFashion python sdk

AF Open API

This project is a wrap of url API provided by AIFashion company. It can automatically process authorization, and renew token when it is expiring. All functions are provided as a function within a object, which is very convenient.

ID & Secret

You need to visit console to regist an account at first, login and create application to get the ID & Secret.

Installation

You can use pip to install this sdk

pip install aifashion_sdk

Usage

Use AIFashion python sdk with

import aifashion

client_id = 'XXXXX'
client_secret = 'YYYYY'
af = aifashion.AIFashionFunctions(client_id=client_id, client_secret=client_secret)

or you can store the ID & Secret in a yaml file

import aifashion

client_filename = 'ZZZZ.yml'
af = aifashion.AIFashionFunctions(client_filename=client_filename)

Then you can call the functions inside af object, a typical calling is like this

# if image_url is given
image_url = 'some url here'
af.a_function(image_url=image_url)

# if image_filename is given
image_filename = 'some filename here'
af.a_function(image_fname=image_filename)

# if image_base64 string is given
image_base64 = 'some base64 here'
af.a_function(image_base64=image_base64)

e.g.

>>> af.fahsion_tagging(image_url='https://images.aifashion.com/01/0f/c7/010fc7622b1b75f7d580137636f25d88.jpg')
{'image': {'height': 640, 'id': '010fc7622b1b75f7d580137636f25d88', 'url': 'https://images.aifashion.com/01/0f/c7/010fc7622b1b75f7d580137636f25d88.jpg', 'width': 640}, 'object': {'category': '箱包', 'category_id': 501, 'confidence': 0.9646803140640259, 'region': {'x1': 0.07128814697265624, 'x2': 0.9111869812011719, 'y1': 0.041831283569335936, 'y2': 0.9469302368164062}}, 'request_id': '855be4d7-7896-4428-bcf1-507a89a835c5#359895', 'tags': [{'key': '风格', 'values': [{'confidence': 0.26829038772796976, 'value': '韩版'}]}, {'key': '款式', 'values': [{'confidence': 0.7964576377930703, 'value': '单肩包'}]}, {'key': '大小', 'values': [{'confidence': 0.5306223626645841, 'value': '小'}]}, {'key': '图案', 'values': [{'confidence': 0.44190941484801455, 'value': '纯色'}]}, {'key': '适用场景', 'values': [{'confidence': 0.959326524265762, 'value': '休闲'}]}, {'key': '闭合方式', 'values': [{'confidence': 0.6383202888420646, 'value': '拉链'}]}, {'key': '形状', 'values': [{'confidence': 0.44122126961424496, 'value': '横款方形'}]}, {'key': '性别', 'values': [{'confidence': 1.0, 'value': '通用'}]}, {'key': '二级类别', 'values': [{'confidence': 0.81, 'value': '挎包'}]}]}

>>> af.color_analysis(image_fname="dress.jpeg")
{'colors': [{'name_en': 'AntiqueWhite', 'name_zh': '浅橙色', 'percentage': 0.1646513949747629, 'rgb': '#F6EBDD'}, {'name_en': 'DimGray', 'name_zh': '黑灰色', 'percentage': 0.388586906280622, 'rgb': '#5B575A'}, {'name_en': 'Salmon', 'name_zh': '西瓜红', 'percentage': 0.16732301662136928, 'rgb': '#E8696D'}, {'name_en': 'DarkSalmon', 'name_zh': '西瓜红', 'percentage': 0.23548634607206909, 'rgb': '#EF9E97'}, {'name_en': 'SaddleBrown', 'name_zh': '深棕色', 'percentage': 0.04395233605117681, 'rgb': '#5B231C'}], 'image': {'height': 640, 'id': '010fc7622b1b75f7d580137636f25d88', 'url': 'https://images.aifashion.com/01/0f/c7/010fc7622b1b75f7d580137636f25d88.jpg', 'width': 640}, 'object': {'category': '短裙', 'category_id': 301, 'confidence': 0.8859304785728455, 'region': {'x1': 0.06238516420125961, 'x2': 0.9350795149803162, 'y1': 0.019997864961624146, 'y2': 0.9653385281562805}}, 'request_id': '855be4d7-7896-4428-bcf1-507a89a835c5#359896'}

>>> af.clothes_detect(image_fname="red_dress.jpeg")
{'image': {'height': 541, 'id': '2755c68dfc1b44301219bc9f399b3148', 'url': 'https://images.aifashion.com/27/55/c6/2755c68dfc1b44301219bc9f399b3148.jpg', 'width': 500}, 'objects': [{'category': '连衣裙', 'category_id': 302, 'confidence': 0.9999842643737793, 'region': {'x1': 0.15614866256713866, 'x2': 0.8775624847412109, 'y1': 0.22497901348686994, 'y2': 0.9921972458030277}}], 'request_id': '5ec403e2-d5f1-4dc3-aa51-0109c6e43b56#363567'}

Metadata

Release files for aifashion-sdk 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aifashion-sdk 1.2.0
File Size Uploaded Provenance Actions
aifashion_sdk-1.2.0.tar.gz 15.1 kB Without provenance Details for aifashion_sdk-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aifashion-sdk 1.2.0
File Interpreter ABI Platform Actions
aifashion_sdk-1.2.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for aifashion_sdk-1.2.0-py2.py3-none-any.whl

Total release size: 31.5 kB

Release files / aifashion_sdk-1.2.0.tar.gz

Download URL aifashion_sdk-1.2.0.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5244db698f884d06260f74d8834ffbfb867d5a9acdb4493564ee640400405da7
BLAKE2b-256 checksum
How to use checksums
4eb07e648b984f98e2bf4dc48a506d5ba2f6259ed781fc61694f7b12543b5fad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

Release files / aifashion_sdk-1.2.0-py2.py3-none-any.whl

Download URL aifashion_sdk-1.2.0-py2.py3-none-any.whl
Size 16.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ab244e51d0a46f9412cc60ff3669532a59d15925828bbe6e522c706a86f046f6
BLAKE2b-256 checksum
How to use checksums
fb20ea6aeccd5e9df003e8a3bd571be809b68e1e29bf5723ec33ce107b03909b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

Security for aifashion-sdk 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page