forked from StartHua/Comfyui_ALY
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlyVision.py
97 lines (89 loc) · 3.31 KB
/
AlyVision.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import json
import os
import folder_paths
from alibabacloud_imageseg20191230.client import Client as imageseg20191230Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imageseg20191230 import models as imageseg_20191230_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_console.client import Client as ConsoleClient
from alibabacloud_tea_util.client import Client as UtilClient
comfy_path = os.path.dirname(folder_paths.__file__)
custom_nodes_path = os.path.join(comfy_path, "custom_nodes")
mine_path = os.path.join(custom_nodes_path, "Comfyui_ALY")
key_json = os.path.join(mine_path, "AssetKey.json")
class AlyVision_imageseg:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> imageseg20191230Client:
"""
使用AK&SK初始化账号Client
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,您的 AccessKey ID,
access_key_id=access_key_id,
# 必填,您的 AccessKey Secret,
access_key_secret=access_key_secret
)
# Endpoint 请参考 https://api.aliyun.com/product/imageseg
config.endpoint = f'imageseg.cn-shanghai.aliyuncs.com'
return imageseg20191230Client(config)
@staticmethod
def create_client_json(
) -> imageseg20191230Client:
"""
使用AK&SK初始化账号Client
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
# 读取json文件
with open(key_json, 'r', encoding='utf-8') as file:
data = json.load(file)
access_key_id = data["access_key_id"]
access_key_secret = data["access_key_secret"]
config = open_api_models.Config(
# 必填,您的 AccessKey ID,
access_key_id=access_key_id,
# 必填,您的 AccessKey Secret,
access_key_secret=access_key_secret
)
# Endpoint 请参考 https://api.aliyun.com/product/imageseg
config.endpoint = f'imageseg.cn-shanghai.aliyuncs.com'
return imageseg20191230Client(config)
@staticmethod
def create_client_with_sts(
access_key_id: str,
access_key_secret: str,
security_token: str,
) -> imageseg20191230Client:
"""
使用STS鉴权方式初始化账号Client,推荐此方式。
@param access_key_id:
@param access_key_secret:
@param security_token:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,您的 AccessKey ID,
access_key_id=access_key_id,
# 必填,您的 AccessKey Secret,
access_key_secret=access_key_secret,
# 必填,您的 Security Token,
security_token=security_token,
# 必填,表明使用 STS 方式,
type='sts'
)
# Endpoint 请参考 https://api.aliyun.com/product/imageseg
config.endpoint = f'imageseg.cn-shanghai.aliyuncs.com'
return imageseg20191230Client(config)
imagese = AlyVision_imageseg()