aimodelshare 0.3.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aimodelshare/README.md +26 -0
- aimodelshare/__init__.py +100 -0
- aimodelshare/aimsonnx.py +2381 -0
- aimodelshare/api.py +836 -0
- aimodelshare/auth.py +163 -0
- aimodelshare/aws.py +511 -0
- aimodelshare/aws_client.py +173 -0
- aimodelshare/base_image.py +154 -0
- aimodelshare/bucketpolicy.py +106 -0
- aimodelshare/color_mappings/color_mapping_keras.csv +121 -0
- aimodelshare/color_mappings/color_mapping_pytorch.csv +117 -0
- aimodelshare/containerisation.py +244 -0
- aimodelshare/containerization.py +712 -0
- aimodelshare/containerization_templates/Dockerfile.txt +8 -0
- aimodelshare/containerization_templates/Dockerfile_PySpark.txt +23 -0
- aimodelshare/containerization_templates/buildspec.txt +14 -0
- aimodelshare/containerization_templates/lambda_function.txt +40 -0
- aimodelshare/custom_approach/__init__.py +1 -0
- aimodelshare/custom_approach/lambda_function.py +17 -0
- aimodelshare/custom_eval_metrics.py +103 -0
- aimodelshare/data_sharing/__init__.py +0 -0
- aimodelshare/data_sharing/data_sharing_templates/Dockerfile.txt +3 -0
- aimodelshare/data_sharing/data_sharing_templates/__init__.py +1 -0
- aimodelshare/data_sharing/data_sharing_templates/buildspec.txt +15 -0
- aimodelshare/data_sharing/data_sharing_templates/codebuild_policies.txt +129 -0
- aimodelshare/data_sharing/data_sharing_templates/codebuild_trust_relationship.txt +12 -0
- aimodelshare/data_sharing/download_data.py +620 -0
- aimodelshare/data_sharing/share_data.py +373 -0
- aimodelshare/data_sharing/utils.py +8 -0
- aimodelshare/deploy_custom_lambda.py +246 -0
- aimodelshare/documentation/Makefile +20 -0
- aimodelshare/documentation/karma_sphinx_theme/__init__.py +28 -0
- aimodelshare/documentation/karma_sphinx_theme/_version.py +2 -0
- aimodelshare/documentation/karma_sphinx_theme/breadcrumbs.html +70 -0
- aimodelshare/documentation/karma_sphinx_theme/layout.html +172 -0
- aimodelshare/documentation/karma_sphinx_theme/search.html +50 -0
- aimodelshare/documentation/karma_sphinx_theme/searchbox.html +14 -0
- aimodelshare/documentation/karma_sphinx_theme/static/css/custom.css +2 -0
- aimodelshare/documentation/karma_sphinx_theme/static/css/custom.css.map +1 -0
- aimodelshare/documentation/karma_sphinx_theme/static/css/theme.css +2751 -0
- aimodelshare/documentation/karma_sphinx_theme/static/css/theme.css.map +1 -0
- aimodelshare/documentation/karma_sphinx_theme/static/css/theme.min.css +2 -0
- aimodelshare/documentation/karma_sphinx_theme/static/css/theme.min.css.map +1 -0
- aimodelshare/documentation/karma_sphinx_theme/static/font/fontello.eot +0 -0
- aimodelshare/documentation/karma_sphinx_theme/static/font/fontello.svg +32 -0
- aimodelshare/documentation/karma_sphinx_theme/static/font/fontello.ttf +0 -0
- aimodelshare/documentation/karma_sphinx_theme/static/font/fontello.woff +0 -0
- aimodelshare/documentation/karma_sphinx_theme/static/font/fontello.woff2 +0 -0
- aimodelshare/documentation/karma_sphinx_theme/static/js/theme.js +68 -0
- aimodelshare/documentation/karma_sphinx_theme/theme.conf +9 -0
- aimodelshare/documentation/make.bat +35 -0
- aimodelshare/documentation/requirements.txt +2 -0
- aimodelshare/documentation/source/about.rst +18 -0
- aimodelshare/documentation/source/advanced_features.rst +137 -0
- aimodelshare/documentation/source/competition.rst +218 -0
- aimodelshare/documentation/source/conf.py +58 -0
- aimodelshare/documentation/source/create_credentials.rst +86 -0
- aimodelshare/documentation/source/example_notebooks.rst +132 -0
- aimodelshare/documentation/source/functions.rst +151 -0
- aimodelshare/documentation/source/gettingstarted.rst +390 -0
- aimodelshare/documentation/source/images/creds1.png +0 -0
- aimodelshare/documentation/source/images/creds2.png +0 -0
- aimodelshare/documentation/source/images/creds3.png +0 -0
- aimodelshare/documentation/source/images/creds4.png +0 -0
- aimodelshare/documentation/source/images/creds5.png +0 -0
- aimodelshare/documentation/source/images/creds_file_example.png +0 -0
- aimodelshare/documentation/source/images/predict_tab.png +0 -0
- aimodelshare/documentation/source/index.rst +110 -0
- aimodelshare/documentation/source/modelplayground.rst +132 -0
- aimodelshare/exceptions.py +11 -0
- aimodelshare/generatemodelapi.py +1270 -0
- aimodelshare/iam/codebuild_policy.txt +129 -0
- aimodelshare/iam/codebuild_trust_relationship.txt +12 -0
- aimodelshare/iam/lambda_policy.txt +15 -0
- aimodelshare/iam/lambda_trust_relationship.txt +12 -0
- aimodelshare/json_templates/__init__.py +1 -0
- aimodelshare/json_templates/api_json.txt +155 -0
- aimodelshare/json_templates/auth/policy.txt +1 -0
- aimodelshare/json_templates/auth/role.txt +1 -0
- aimodelshare/json_templates/eval/policy.txt +1 -0
- aimodelshare/json_templates/eval/role.txt +1 -0
- aimodelshare/json_templates/function/policy.txt +1 -0
- aimodelshare/json_templates/function/role.txt +1 -0
- aimodelshare/json_templates/integration_response.txt +5 -0
- aimodelshare/json_templates/lambda_policy_1.txt +15 -0
- aimodelshare/json_templates/lambda_policy_2.txt +8 -0
- aimodelshare/json_templates/lambda_role_1.txt +12 -0
- aimodelshare/json_templates/lambda_role_2.txt +16 -0
- aimodelshare/leaderboard.py +174 -0
- aimodelshare/main/1.txt +132 -0
- aimodelshare/main/1B.txt +112 -0
- aimodelshare/main/2.txt +153 -0
- aimodelshare/main/3.txt +134 -0
- aimodelshare/main/4.txt +128 -0
- aimodelshare/main/5.txt +109 -0
- aimodelshare/main/6.txt +105 -0
- aimodelshare/main/7.txt +144 -0
- aimodelshare/main/8.txt +142 -0
- aimodelshare/main/__init__.py +1 -0
- aimodelshare/main/authorization.txt +275 -0
- aimodelshare/main/eval_classification.txt +79 -0
- aimodelshare/main/eval_lambda.txt +1709 -0
- aimodelshare/main/eval_regression.txt +80 -0
- aimodelshare/main/lambda_function.txt +8 -0
- aimodelshare/main/nst.txt +149 -0
- aimodelshare/model.py +1543 -0
- aimodelshare/modeluser.py +215 -0
- aimodelshare/moral_compass/README.md +408 -0
- aimodelshare/moral_compass/__init__.py +65 -0
- aimodelshare/moral_compass/_version.py +3 -0
- aimodelshare/moral_compass/api_client.py +601 -0
- aimodelshare/moral_compass/apps/__init__.py +69 -0
- aimodelshare/moral_compass/apps/ai_consequences.py +540 -0
- aimodelshare/moral_compass/apps/bias_detective.py +714 -0
- aimodelshare/moral_compass/apps/ethical_revelation.py +898 -0
- aimodelshare/moral_compass/apps/fairness_fixer.py +889 -0
- aimodelshare/moral_compass/apps/judge.py +888 -0
- aimodelshare/moral_compass/apps/justice_equity_upgrade.py +853 -0
- aimodelshare/moral_compass/apps/mc_integration_helpers.py +820 -0
- aimodelshare/moral_compass/apps/model_building_game.py +1104 -0
- aimodelshare/moral_compass/apps/model_building_game_beginner.py +687 -0
- aimodelshare/moral_compass/apps/moral_compass_challenge.py +858 -0
- aimodelshare/moral_compass/apps/session_auth.py +254 -0
- aimodelshare/moral_compass/apps/shared_activity_styles.css +349 -0
- aimodelshare/moral_compass/apps/tutorial.py +481 -0
- aimodelshare/moral_compass/apps/what_is_ai.py +853 -0
- aimodelshare/moral_compass/challenge.py +365 -0
- aimodelshare/moral_compass/config.py +187 -0
- aimodelshare/placeholders/model.onnx +0 -0
- aimodelshare/placeholders/preprocessor.zip +0 -0
- aimodelshare/playground.py +1968 -0
- aimodelshare/postprocessormodules.py +157 -0
- aimodelshare/preprocessormodules.py +373 -0
- aimodelshare/pyspark/1.txt +195 -0
- aimodelshare/pyspark/1B.txt +181 -0
- aimodelshare/pyspark/2.txt +220 -0
- aimodelshare/pyspark/3.txt +204 -0
- aimodelshare/pyspark/4.txt +187 -0
- aimodelshare/pyspark/5.txt +178 -0
- aimodelshare/pyspark/6.txt +174 -0
- aimodelshare/pyspark/7.txt +211 -0
- aimodelshare/pyspark/8.txt +206 -0
- aimodelshare/pyspark/__init__.py +1 -0
- aimodelshare/pyspark/authorization.txt +258 -0
- aimodelshare/pyspark/eval_classification.txt +79 -0
- aimodelshare/pyspark/eval_lambda.txt +1441 -0
- aimodelshare/pyspark/eval_regression.txt +80 -0
- aimodelshare/pyspark/lambda_function.txt +8 -0
- aimodelshare/pyspark/nst.txt +213 -0
- aimodelshare/python/my_preprocessor.py +58 -0
- aimodelshare/readme.md +26 -0
- aimodelshare/reproducibility.py +181 -0
- aimodelshare/sam/Dockerfile.txt +8 -0
- aimodelshare/sam/Dockerfile_PySpark.txt +24 -0
- aimodelshare/sam/__init__.py +1 -0
- aimodelshare/sam/buildspec.txt +11 -0
- aimodelshare/sam/codebuild_policies.txt +129 -0
- aimodelshare/sam/codebuild_trust_relationship.txt +12 -0
- aimodelshare/sam/codepipeline_policies.txt +173 -0
- aimodelshare/sam/codepipeline_trust_relationship.txt +12 -0
- aimodelshare/sam/spark-class.txt +2 -0
- aimodelshare/sam/template.txt +54 -0
- aimodelshare/tools.py +103 -0
- aimodelshare/utils/__init__.py +78 -0
- aimodelshare/utils/optional_deps.py +38 -0
- aimodelshare/utils.py +57 -0
- aimodelshare-0.3.7.dist-info/METADATA +298 -0
- aimodelshare-0.3.7.dist-info/RECORD +171 -0
- aimodelshare-0.3.7.dist-info/WHEEL +5 -0
- aimodelshare-0.3.7.dist-info/licenses/LICENSE +5 -0
- aimodelshare-0.3.7.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import json
|
|
3
|
+
import boto3
|
|
4
|
+
|
|
5
|
+
delay=2
|
|
6
|
+
|
|
7
|
+
class AWSClient():
|
|
8
|
+
|
|
9
|
+
def __init__(self, user_session):
|
|
10
|
+
|
|
11
|
+
self.ecr_client = user_session.client('ecr')
|
|
12
|
+
self.s3_client = user_session.client("s3")
|
|
13
|
+
self.iam_client = user_session.client("iam")
|
|
14
|
+
self.sts_client = user_session.client("sts")
|
|
15
|
+
self.lambda_client = user_session.client("lambda")
|
|
16
|
+
self.codebuild_client = user_session.client("codebuild")
|
|
17
|
+
self.apigateway_client = user_session.client("apigateway")
|
|
18
|
+
self.account_id = self.sts_client.get_caller_identity()["Account"]
|
|
19
|
+
|
|
20
|
+
def get_repository_details(self, repository_name):
|
|
21
|
+
try:
|
|
22
|
+
response = self.ecr_client.describe_repositories(repositoryNames=[repository_name])
|
|
23
|
+
repository_details = response['repositories']
|
|
24
|
+
except:
|
|
25
|
+
repository_details = []
|
|
26
|
+
return repository_details
|
|
27
|
+
|
|
28
|
+
def get_image_details(self, repository_name, image_tag):
|
|
29
|
+
try:
|
|
30
|
+
response = self.ecr_client.describe_images(repositoryName=repository_name, imageIds=[{'imageTag': image_tag}])
|
|
31
|
+
image_details = response['imageDetails']
|
|
32
|
+
except:
|
|
33
|
+
image_details = []
|
|
34
|
+
return image_details
|
|
35
|
+
|
|
36
|
+
def get_role_details(self, role_name):
|
|
37
|
+
try:
|
|
38
|
+
response = self.iam_client.get_role(RoleName=role_name)
|
|
39
|
+
role_details = response['Role']
|
|
40
|
+
except:
|
|
41
|
+
role_details = {}
|
|
42
|
+
return role_details
|
|
43
|
+
|
|
44
|
+
def get_policy_details(self, policy_arn):
|
|
45
|
+
try:
|
|
46
|
+
response = self.iam_client.get_policy(PolicyArn=policy_arn)
|
|
47
|
+
policy_details = response['Policy']
|
|
48
|
+
except:
|
|
49
|
+
policy_details = {}
|
|
50
|
+
return policy_details
|
|
51
|
+
|
|
52
|
+
def detach_policies_from_role(self, role_name):
|
|
53
|
+
response = self.iam_client.list_attached_role_policies(RoleName=role_name)
|
|
54
|
+
policies = response['AttachedPolicies']
|
|
55
|
+
for policy in policies:
|
|
56
|
+
response = self.iam_client.detach_role_policy(RoleName=role_name, PolicyArn=policy['PolicyArn'])
|
|
57
|
+
time.sleep(delay)
|
|
58
|
+
|
|
59
|
+
def delete_iam_role(self, role_name):
|
|
60
|
+
if(len(self.get_role_details(role_name))):
|
|
61
|
+
response = self.detach_policies_from_role(role_name)
|
|
62
|
+
response = self.iam_client.delete_role(RoleName=role_name)
|
|
63
|
+
time.sleep(delay)
|
|
64
|
+
|
|
65
|
+
def delete_iam_policy(self, policy_name):
|
|
66
|
+
policy_arn = "arn:aws:iam::" + self.account_id + ":policy/" + policy_name
|
|
67
|
+
if(len(self.get_policy_details(policy_arn))):
|
|
68
|
+
response = self.iam_client.delete_policy(PolicyArn=policy_arn)
|
|
69
|
+
time.sleep(delay)
|
|
70
|
+
|
|
71
|
+
def create_iam_role(self, role_name, trust_relationship):
|
|
72
|
+
response = self.iam_client.create_role(RoleName=role_name, AssumeRolePolicyDocument=json.dumps(trust_relationship))
|
|
73
|
+
time.sleep(delay)
|
|
74
|
+
|
|
75
|
+
def create_iam_policy(self, policy_name, policy):
|
|
76
|
+
policy_arn = "arn:aws:iam::" + self.account_id + ":policy/" + policy_name
|
|
77
|
+
response = self.iam_client.create_policy(PolicyName=policy_name, PolicyDocument=json.dumps(policy))
|
|
78
|
+
time.sleep(delay)
|
|
79
|
+
|
|
80
|
+
def attach_policy_to_role(self, role_name, policy_name):
|
|
81
|
+
policy_arn = "arn:aws:iam::" + self.account_id + ":policy/" + policy_name
|
|
82
|
+
response = self.iam_client.attach_role_policy(RoleName = role_name, PolicyArn = policy_arn)
|
|
83
|
+
time.sleep(delay)
|
|
84
|
+
|
|
85
|
+
def create_repository(self, repository_name):
|
|
86
|
+
response = self.ecr_client.create_repository(repositoryName=repository_name)
|
|
87
|
+
time.sleep(delay)
|
|
88
|
+
|
|
89
|
+
def delete_repository(self, repository_name):
|
|
90
|
+
pass
|
|
91
|
+
time.sleep(delay)
|
|
92
|
+
|
|
93
|
+
def upload_file_to_s3(self, local_file_path, bucket_name, bucket_file_path):
|
|
94
|
+
response = self.s3_client.upload_file(local_file_path, bucket_name, bucket_file_path)
|
|
95
|
+
time.sleep(delay)
|
|
96
|
+
|
|
97
|
+
def delete_file_from_s3(self, bucket_name, bucket_file_path):
|
|
98
|
+
response = self.s3_client.delete_object(Bucket=bucket_name, Key=bucket_file_path)
|
|
99
|
+
time.sleep(delay)
|
|
100
|
+
|
|
101
|
+
def create_s3_bucket(self, bucket_name, region):
|
|
102
|
+
try:
|
|
103
|
+
response=self.s3_client.head_bucket(Bucket=bucket_name)
|
|
104
|
+
except:
|
|
105
|
+
if(region=="us-east-1"):
|
|
106
|
+
response = self.s3_client.create_bucket(
|
|
107
|
+
ACL="private",
|
|
108
|
+
Bucket=bucket_name
|
|
109
|
+
)
|
|
110
|
+
else:
|
|
111
|
+
location = {'LocationConstraint': region}
|
|
112
|
+
response = self.s3_client.create_bucket(
|
|
113
|
+
ACL="private",
|
|
114
|
+
Bucket=bucket_name,
|
|
115
|
+
CreateBucketConfiguration=location
|
|
116
|
+
)
|
|
117
|
+
return response
|
|
118
|
+
|
|
119
|
+
####################################################################################################
|
|
120
|
+
|
|
121
|
+
def add_invoke_resource_policy_to_lambda(self, lambda_function, statement_id, source_arn):
|
|
122
|
+
response = self.lambda_client.add_permission(
|
|
123
|
+
FunctionName=lambda_function,
|
|
124
|
+
StatementId=statement_id,
|
|
125
|
+
Action='lambda:InvokeFunction',
|
|
126
|
+
Principal='apigateway.amazonaws.com',
|
|
127
|
+
SourceArn=source_arn
|
|
128
|
+
)
|
|
129
|
+
return response
|
|
130
|
+
|
|
131
|
+
def get_api_resources(self, api_id):
|
|
132
|
+
try:
|
|
133
|
+
response = self.apigateway_client.get_resources(restApiId=api_id)
|
|
134
|
+
resources = response['items']
|
|
135
|
+
except:
|
|
136
|
+
resources = []
|
|
137
|
+
return resources
|
|
138
|
+
|
|
139
|
+
def integration_setup(self, api_id, resource_id, uri_str, credentials, integration_response):
|
|
140
|
+
response_1 = self.apigateway_client.put_integration(
|
|
141
|
+
restApiId=api_id,
|
|
142
|
+
resourceId=resource_id,
|
|
143
|
+
httpMethod='POST',
|
|
144
|
+
type='AWS_PROXY',
|
|
145
|
+
integrationHttpMethod='POST',
|
|
146
|
+
uri=uri_str,
|
|
147
|
+
credentials=credentials
|
|
148
|
+
)
|
|
149
|
+
response_2 = self.apigateway_client.put_integration(
|
|
150
|
+
restApiId=api_id,
|
|
151
|
+
resourceId=resource_id,
|
|
152
|
+
httpMethod='OPTIONS',
|
|
153
|
+
type='MOCK',
|
|
154
|
+
requestTemplates={"application/json": '{"statusCode": 200}'},
|
|
155
|
+
integrationHttpMethod='OPTIONS',
|
|
156
|
+
uri=uri_str,
|
|
157
|
+
credentials=credentials
|
|
158
|
+
)
|
|
159
|
+
response_3 = self.apigateway_client.put_integration(
|
|
160
|
+
restApiId=api_id,
|
|
161
|
+
resourceId=resource_id,
|
|
162
|
+
httpMethod='OPTIONS',
|
|
163
|
+
type='MOCK',
|
|
164
|
+
requestTemplates={"application/json": '{"statusCode": 200}'}
|
|
165
|
+
)
|
|
166
|
+
response_4 = self.apigateway_client.put_integration_response(
|
|
167
|
+
restApiId=api_id,
|
|
168
|
+
resourceId=resource_id,
|
|
169
|
+
httpMethod='OPTIONS',
|
|
170
|
+
statusCode='200',
|
|
171
|
+
responseParameters=integration_response,
|
|
172
|
+
responseTemplates={"application/json": '{"statusCode": 200}'}
|
|
173
|
+
)
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import boto3
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
import time
|
|
6
|
+
import tempfile
|
|
7
|
+
import zipfile
|
|
8
|
+
import importlib.resources as pkg_resources
|
|
9
|
+
from string import Template
|
|
10
|
+
|
|
11
|
+
def lambda_using_base_image(account_id, region, session, project_name, model_dir, requirements_file_path, apiid, memory_size='3000', timeout='90', python_version='3.7'):
|
|
12
|
+
|
|
13
|
+
codebuild_bucket_name=os.environ.get("BUCKET_NAME") # s3 bucket name to create #TODO: use same bucket and subfolder we used previously to store this data
|
|
14
|
+
#Why? AWS limits users to 100 total buckets! Our old code only creates one per user per acct.
|
|
15
|
+
|
|
16
|
+
repository=project_name+'-repository' # repository name to create
|
|
17
|
+
|
|
18
|
+
template_folder=tempfile.gettempdir()+'/'+project_name # folder to create for sam
|
|
19
|
+
|
|
20
|
+
stack_name=project_name+'-stack' # stack name to be created in cloudformation
|
|
21
|
+
|
|
22
|
+
docker_tag='latest'
|
|
23
|
+
function_name=project_name
|
|
24
|
+
role_name=project_name+'-lambda-role'
|
|
25
|
+
policy_name=project_name+'-lambda-policy'
|
|
26
|
+
|
|
27
|
+
codebuild_role_name=project_name+'-codebuild-role'
|
|
28
|
+
codebuild_policies_name=project_name+'-codebuild-policies'
|
|
29
|
+
|
|
30
|
+
codebuild_project_name=project_name+'-project'
|
|
31
|
+
|
|
32
|
+
s3_client = session.resource('s3', region_name=region)
|
|
33
|
+
|
|
34
|
+
s3_resource = session.resource('s3', region_name=region)
|
|
35
|
+
|
|
36
|
+
bucket_versioning = s3_resource.BucketVersioning(codebuild_bucket_name)
|
|
37
|
+
response = bucket_versioning.enable()
|
|
38
|
+
|
|
39
|
+
ecr = session.client('ecr')
|
|
40
|
+
|
|
41
|
+
response = ecr.create_repository(
|
|
42
|
+
repositoryName=repository
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
iam = session.client('iam')
|
|
46
|
+
|
|
47
|
+
import importlib_resources as pkg_resources
|
|
48
|
+
#from . import sam
|
|
49
|
+
|
|
50
|
+
os.mkdir(template_folder)
|
|
51
|
+
|
|
52
|
+
response = shutil.copytree(model_dir, '/'.join([template_folder, model_dir]))
|
|
53
|
+
|
|
54
|
+
def get_all_file_paths(directory):
|
|
55
|
+
file_paths = []
|
|
56
|
+
for root, directories, files in os.walk(directory):
|
|
57
|
+
for filename in files:
|
|
58
|
+
filepath = os.path.join(root, filename)
|
|
59
|
+
file_paths.append(filepath)
|
|
60
|
+
return file_paths
|
|
61
|
+
|
|
62
|
+
file_paths = get_all_file_paths(template_folder)
|
|
63
|
+
|
|
64
|
+
template_folder_len = len(template_folder)
|
|
65
|
+
|
|
66
|
+
with zipfile.ZipFile(''.join([template_folder, '.zip']),'w') as zip:
|
|
67
|
+
for file in file_paths:
|
|
68
|
+
zip.write(file, file[template_folder_len:])
|
|
69
|
+
|
|
70
|
+
s3_client = session.client('s3')
|
|
71
|
+
s3_client.upload_file(''.join([template_folder, '.zip']),
|
|
72
|
+
codebuild_bucket_name,
|
|
73
|
+
''.join([apiid, '/', project_name, '.zip']))
|
|
74
|
+
|
|
75
|
+
iam_client = session.client('iam')
|
|
76
|
+
|
|
77
|
+
response = iam_client.create_policy(
|
|
78
|
+
PolicyName=policy_name,
|
|
79
|
+
PolicyDocument=json.dumps({
|
|
80
|
+
"Version": "2012-10-17",
|
|
81
|
+
"Statement": [
|
|
82
|
+
{
|
|
83
|
+
"Action": "logs:CreateLogStream",
|
|
84
|
+
"Resource": "*",
|
|
85
|
+
"Effect": "Allow"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"Action": "logs:PutLogEvents",
|
|
89
|
+
"Resource": "*",
|
|
90
|
+
"Effect": "Allow"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"Action": "s3:*",
|
|
94
|
+
"Resource": "*",
|
|
95
|
+
"Effect": "Allow"
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
})
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
time.sleep(5)
|
|
102
|
+
|
|
103
|
+
response = iam_client.create_role(
|
|
104
|
+
RoleName=role_name,
|
|
105
|
+
AssumeRolePolicyDocument=json.dumps({
|
|
106
|
+
"Version": "2012-10-17",
|
|
107
|
+
"Statement": [
|
|
108
|
+
{
|
|
109
|
+
"Effect": "Allow",
|
|
110
|
+
"Principal": {
|
|
111
|
+
"Service": "lambda.amazonaws.com"
|
|
112
|
+
},
|
|
113
|
+
"Action": "sts:AssumeRole"
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
})
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
time.sleep(5)
|
|
120
|
+
|
|
121
|
+
response = iam_client.attach_role_policy(
|
|
122
|
+
RoleName=role_name,
|
|
123
|
+
PolicyArn='arn:aws:iam::' + account_id + ':policy/' + policy_name
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
time.sleep(5)
|
|
127
|
+
|
|
128
|
+
lambda_client = session.client('lambda')
|
|
129
|
+
|
|
130
|
+
response = lambda_client.create_function(
|
|
131
|
+
FunctionName=project_name,
|
|
132
|
+
Role='arn:aws:iam::' + account_id + ':role/' + role_name,
|
|
133
|
+
Code={
|
|
134
|
+
'ImageUri': account_id + '.dkr.ecr.' + region + '.amazonaws.com/aimodelshare-base-image:latest'
|
|
135
|
+
},
|
|
136
|
+
PackageType="Image",
|
|
137
|
+
Timeout=int(timeout),
|
|
138
|
+
MemorySize=int(memory_size),
|
|
139
|
+
Environment={
|
|
140
|
+
'Variables': {
|
|
141
|
+
'bucket': codebuild_bucket_name,
|
|
142
|
+
'key': apiid + '/' + project_name + '.zip',
|
|
143
|
+
'final_location': '/tmp/' + model_dir + '.zip'
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
s3_client.delete_object(Bucket=codebuild_bucket_name, Key=apiid)
|
|
149
|
+
|
|
150
|
+
shutil.rmtree(template_folder)
|
|
151
|
+
|
|
152
|
+
__all__ = [
|
|
153
|
+
lambda_using_base_image
|
|
154
|
+
]
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
def _custom_s3_policy(bucketname):
|
|
2
|
+
this_policy = {
|
|
3
|
+
"Version": "2012-10-17",
|
|
4
|
+
"Statement": [
|
|
5
|
+
{
|
|
6
|
+
"Effect": "Allow",
|
|
7
|
+
"Action": "s3:*",
|
|
8
|
+
"Resource": [
|
|
9
|
+
"arn:aws:s3:::"+bucketname,
|
|
10
|
+
"arn:aws:s3:::"+bucketname+"/*"
|
|
11
|
+
]
|
|
12
|
+
},{
|
|
13
|
+
"Effect": "Allow",
|
|
14
|
+
"Action": "apigateway:*",
|
|
15
|
+
"Resource":"*"
|
|
16
|
+
},{
|
|
17
|
+
"Effect": "Allow",
|
|
18
|
+
"Action": "lambda:*",
|
|
19
|
+
"Resource":"*"
|
|
20
|
+
},{
|
|
21
|
+
"Effect": "Allow",
|
|
22
|
+
"Action": "sts:GetCallerIdentity",
|
|
23
|
+
"Resource":"*"
|
|
24
|
+
},{
|
|
25
|
+
"Effect": "Allow",
|
|
26
|
+
"Action": ["iam:ListRoles","iam:PutRolePolicy","iam:CreateRole", "iam:ListRolePolicies", "iam:ListAttachedRolePolicies","iam:GetRole","iam:PassRole"],
|
|
27
|
+
"Resource":[ "arn:aws:lambda:*:*:function:*", "arn:aws:iam::*:role/*","arn:aws:apigateway:*:*","arn:aws:execute-api:*:*"]
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return this_policy
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _custom_upload_policy(bucket_name, unique_model_id):
|
|
37
|
+
managed_policy = {
|
|
38
|
+
"Version": "2012-10-17",
|
|
39
|
+
"Statement": [
|
|
40
|
+
{
|
|
41
|
+
"Sid": "AllowUserToSeeBucketListInTheConsole"+str(unique_model_id),
|
|
42
|
+
"Action": [
|
|
43
|
+
"s3:ListAllMyBuckets",
|
|
44
|
+
"s3:GetBucketLocation"
|
|
45
|
+
],
|
|
46
|
+
"Effect": "Allow",
|
|
47
|
+
"Resource": [
|
|
48
|
+
"arn:aws:s3:::*"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"Sid": "AllowRootAndHomeListingOfCompanyBucket"+str(unique_model_id),
|
|
53
|
+
"Action": [
|
|
54
|
+
"s3:ListBucket"
|
|
55
|
+
],
|
|
56
|
+
"Effect": "Allow",
|
|
57
|
+
"Resource": [
|
|
58
|
+
"arn:aws:s3:::"+bucket_name
|
|
59
|
+
],
|
|
60
|
+
"Condition": {
|
|
61
|
+
"StringEquals": {
|
|
62
|
+
"s3:prefix": [
|
|
63
|
+
"",
|
|
64
|
+
unique_model_id+"/"
|
|
65
|
+
],
|
|
66
|
+
"s3:delimiter": [
|
|
67
|
+
"/"
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"Sid": "AllowListingOfUserFolder"+str(unique_model_id),
|
|
74
|
+
"Action": [
|
|
75
|
+
"s3:ListBucket"
|
|
76
|
+
],
|
|
77
|
+
"Effect": "Allow",
|
|
78
|
+
"Resource": [
|
|
79
|
+
"arn:aws:s3:::"+bucket_name
|
|
80
|
+
],
|
|
81
|
+
"Condition": {
|
|
82
|
+
"StringLike": {
|
|
83
|
+
"s3:prefix": [
|
|
84
|
+
unique_model_id+"/*"
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"Sid": "AllowAllS3ActionsInUserFolder"+str(unique_model_id),
|
|
91
|
+
"Effect": "Allow",
|
|
92
|
+
"Action": [
|
|
93
|
+
"s3:*"
|
|
94
|
+
],
|
|
95
|
+
"Resource": [
|
|
96
|
+
"arn:aws:s3:::"+bucket_name+"/"+unique_model_id+"/*"
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
return managed_policy
|
|
102
|
+
|
|
103
|
+
__all__ = [
|
|
104
|
+
_custom_s3_policy,
|
|
105
|
+
_custom_upload_policy,
|
|
106
|
+
]
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
,keras,hex,
|
|
2
|
+
0,AbstractRNNCell,#f1e2cc,
|
|
3
|
+
1,Activation,,
|
|
4
|
+
2,ActivityRegularization,#cbd5e8,
|
|
5
|
+
3,Add,,
|
|
6
|
+
4,AdditiveAttention,#f4cae4,
|
|
7
|
+
5,AlphaDropout,#cbd5e8,
|
|
8
|
+
6,Attention,#f4cae4,
|
|
9
|
+
7,Average,,
|
|
10
|
+
8,AveragePooling1D,#e6f5c9,
|
|
11
|
+
9,AveragePooling2D,#e6f5c9,
|
|
12
|
+
10,AveragePooling3D,#e6f5c9,
|
|
13
|
+
11,AvgPool1D,#e6f5c9,
|
|
14
|
+
12,AvgPool2D,#e6f5c9,
|
|
15
|
+
13,AvgPool3D,#e6f5c9,
|
|
16
|
+
14,BatchNormalization,#cbd5e8,
|
|
17
|
+
15,Bidirectional,#f1e2cc,
|
|
18
|
+
16,CategoryEncoding,,
|
|
19
|
+
17,CenterCrop,,
|
|
20
|
+
18,Concatenate,,
|
|
21
|
+
19,Conv1D,#fdcdac,
|
|
22
|
+
20,Conv1DTranspose,#fdcdac,
|
|
23
|
+
21,Conv2D,#fdcdac,
|
|
24
|
+
22,Conv2DTranspose,#fdcdac,
|
|
25
|
+
23,Conv3D,#fdcdac,
|
|
26
|
+
24,Conv3DTranspose,#fdcdac,
|
|
27
|
+
25,ConvLSTM1D,#fdcdac,
|
|
28
|
+
26,ConvLSTM2D,#fdcdac,
|
|
29
|
+
27,ConvLSTM3D,#fdcdac,
|
|
30
|
+
28,Convolution1D,#fdcdac,
|
|
31
|
+
29,Convolution1DTranspose,#fdcdac,
|
|
32
|
+
30,Convolution2D,#fdcdac,
|
|
33
|
+
31,Convolution2DTranspose,#fdcdac,
|
|
34
|
+
32,Convolution3D,#fdcdac,
|
|
35
|
+
33,Convolution3DTranspose,#fdcdac,
|
|
36
|
+
34,Cropping1D,,
|
|
37
|
+
35,Cropping2D,,
|
|
38
|
+
36,Cropping3D,,
|
|
39
|
+
37,Dense,#fff2ae,
|
|
40
|
+
38,DenseFeatures,,
|
|
41
|
+
39,DepthwiseConv2D,#fdcdac,
|
|
42
|
+
40,Discretization,,
|
|
43
|
+
41,Dot,,
|
|
44
|
+
42,Dropout,#cbd5e8,
|
|
45
|
+
43,Embedding,#b3e2cd,
|
|
46
|
+
44,Flatten,,
|
|
47
|
+
45,GRU,#f1e2cc,
|
|
48
|
+
46,GRUCell,#f1e2cc,
|
|
49
|
+
47,GaussianDropout,#cbd5e8,
|
|
50
|
+
48,GaussianNoise,#cbd5e8,
|
|
51
|
+
49,GlobalAveragePooling1D,#e6f5c9,
|
|
52
|
+
50,GlobalAveragePooling2D,#e6f5c9,
|
|
53
|
+
51,GlobalAveragePooling3D,#e6f5c9,
|
|
54
|
+
52,GlobalAvgPool1D,#e6f5c9,
|
|
55
|
+
53,GlobalAvgPool2D,#e6f5c9,
|
|
56
|
+
54,GlobalAvgPool3D,#e6f5c9,
|
|
57
|
+
55,GlobalMaxPool1D,#e6f5c9,
|
|
58
|
+
56,GlobalMaxPool2D,#e6f5c9,
|
|
59
|
+
57,GlobalMaxPool3D,#e6f5c9,
|
|
60
|
+
58,GlobalMaxPooling1D,#e6f5c9,
|
|
61
|
+
59,GlobalMaxPooling2D,#e6f5c9,
|
|
62
|
+
60,GlobalMaxPooling3D,#e6f5c9,
|
|
63
|
+
61,Hashing,,
|
|
64
|
+
62,Input,,
|
|
65
|
+
63,InputLayer,,
|
|
66
|
+
64,InputSpec,,
|
|
67
|
+
65,IntegerLookup,,
|
|
68
|
+
66,LSTM,#f1e2cc,
|
|
69
|
+
67,LSTMCell,#f1e2cc,
|
|
70
|
+
68,Lambda,,
|
|
71
|
+
69,Layer,,
|
|
72
|
+
70,LayerNormalization,#cbd5e8,
|
|
73
|
+
71,LocallyConnected1D,#fdcdac,
|
|
74
|
+
72,LocallyConnected2D,#fdcdac,
|
|
75
|
+
73,Masking,,
|
|
76
|
+
74,MaxPool1D,#e6f5c9,
|
|
77
|
+
75,MaxPool2D,#e6f5c9,
|
|
78
|
+
76,MaxPool3D,#e6f5c9,
|
|
79
|
+
77,MaxPooling1D,#e6f5c9,
|
|
80
|
+
78,MaxPooling2D,#e6f5c9,
|
|
81
|
+
79,MaxPooling3D,#e6f5c9,
|
|
82
|
+
80,Maximum,,
|
|
83
|
+
81,Minimum,,
|
|
84
|
+
82,MultiHeadAttention,#f4cae4,
|
|
85
|
+
83,Multiply,,
|
|
86
|
+
84,Normalization,,
|
|
87
|
+
85,Permute,,
|
|
88
|
+
86,RNN,#f1e2cc,
|
|
89
|
+
87,RandomContrast,,
|
|
90
|
+
88,RandomCrop,,
|
|
91
|
+
89,RandomFlip,,
|
|
92
|
+
90,RandomHeight,,
|
|
93
|
+
91,RandomRotation,,
|
|
94
|
+
92,RandomTranslation,,
|
|
95
|
+
93,RandomWidth,,
|
|
96
|
+
94,RandomZoom,,
|
|
97
|
+
95,RepeatVector,,
|
|
98
|
+
96,Rescaling,,
|
|
99
|
+
97,Reshape,,
|
|
100
|
+
98,Resizing,,
|
|
101
|
+
99,SeparableConv1D,#fdcdac,
|
|
102
|
+
100,SeparableConv2D,#fdcdac,
|
|
103
|
+
101,SeparableConvolution1D,#fdcdac,
|
|
104
|
+
102,SeparableConvolution2D,#fdcdac,
|
|
105
|
+
103,SimpleRNN,#f1e2cc,
|
|
106
|
+
104,SimpleRNNCell,#f1e2cc,
|
|
107
|
+
105,SpatialDropout1D,#cbd5e8,
|
|
108
|
+
106,SpatialDropout2D,#cbd5e8,
|
|
109
|
+
107,SpatialDropout3D,#cbd5e8,
|
|
110
|
+
108,StackedRNNCells,#f1e2cc,
|
|
111
|
+
109,StringLookup,,
|
|
112
|
+
110,Subtract,,
|
|
113
|
+
111,TextVectorization,,
|
|
114
|
+
112,TimeDistributed,,
|
|
115
|
+
113,UpSampling1D,,
|
|
116
|
+
114,UpSampling2D,,
|
|
117
|
+
115,UpSampling3D,,
|
|
118
|
+
116,Wrapper,,
|
|
119
|
+
117,ZeroPadding1D,#cccccc,
|
|
120
|
+
118,ZeroPadding2D,#cccccc,
|
|
121
|
+
119,ZeroPadding3D,#cccccc,
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
,pytorch,hex
|
|
2
|
+
0,AdaptiveAvgPool1d,#e6f5c9
|
|
3
|
+
1,AdaptiveAvgPool2d,#e6f5c9
|
|
4
|
+
2,AdaptiveAvgPool3d,#e6f5c9
|
|
5
|
+
3,AdaptiveMaxPool1d,#e6f5c9
|
|
6
|
+
4,AdaptiveMaxPool2d,#e6f5c9
|
|
7
|
+
5,AdaptiveMaxPool3d,#e6f5c9
|
|
8
|
+
6,AlphaDropout,#cbd5e8
|
|
9
|
+
7,AvgPool1d,#e6f5c9
|
|
10
|
+
8,AvgPool2d,#e6f5c9
|
|
11
|
+
9,AvgPool3d,#e6f5c9
|
|
12
|
+
10,BatchNorm1d,#cbd5e8
|
|
13
|
+
11,BatchNorm2d,#cbd5e8
|
|
14
|
+
12,BatchNorm3d,#cbd5e8
|
|
15
|
+
13,Bilinear,
|
|
16
|
+
14,ConstantPad1d,#cccccc
|
|
17
|
+
15,ConstantPad2d,#cccccc
|
|
18
|
+
16,ConstantPad3d,#cccccc
|
|
19
|
+
17,Container,
|
|
20
|
+
18,Conv1d,#fdcdac
|
|
21
|
+
19,Conv2d,#fdcdac
|
|
22
|
+
20,Conv3d,#fdcdac
|
|
23
|
+
21,ConvTranspose1d,#fdcdac
|
|
24
|
+
22,ConvTranspose2d,#fdcdac
|
|
25
|
+
23,ConvTranspose3d,#fdcdac
|
|
26
|
+
24,CosineSimilarity,
|
|
27
|
+
25,CrossMapLRN2d,
|
|
28
|
+
26,DataParallel,
|
|
29
|
+
27,Dropout,#cbd5e8
|
|
30
|
+
28,Dropout2d,#cbd5e8
|
|
31
|
+
29,Dropout3d,#cbd5e8
|
|
32
|
+
30,Embedding,#b3e2cd
|
|
33
|
+
31,EmbeddingBag,#b3e2cd
|
|
34
|
+
32,FeatureAlphaDropout,#cbd5e8
|
|
35
|
+
33,Flatten,
|
|
36
|
+
34,Fold,
|
|
37
|
+
35,FractionalMaxPool2d,#e6f5c9
|
|
38
|
+
36,FractionalMaxPool3d,#e6f5c9
|
|
39
|
+
37,GRU,#f1e2cc
|
|
40
|
+
38,GRUCell,#f1e2cc
|
|
41
|
+
39,GroupNorm,
|
|
42
|
+
40,Identity,
|
|
43
|
+
41,InstanceNorm1d,#cbd5e8
|
|
44
|
+
42,InstanceNorm2d,#cbd5e8
|
|
45
|
+
43,InstanceNorm3d,#cbd5e8
|
|
46
|
+
44,LPPool1d,#e6f5c9
|
|
47
|
+
45,LPPool2d,#e6f5c9
|
|
48
|
+
46,LSTM,#f1e2cc
|
|
49
|
+
47,LSTMCell,#f1e2cc
|
|
50
|
+
48,LayerNorm,
|
|
51
|
+
49,Linear,#fff2ae
|
|
52
|
+
50,LocalResponseNorm,
|
|
53
|
+
51,MaxPool1d,#e6f5c9
|
|
54
|
+
52,MaxPool2d,#e6f5c9
|
|
55
|
+
53,MaxPool3d,#e6f5c9
|
|
56
|
+
54,MaxUnpool1d,#e6f5c9
|
|
57
|
+
55,MaxUnpool2d,#e6f5c9
|
|
58
|
+
56,MaxUnpool3d,#e6f5c9
|
|
59
|
+
57,Module,
|
|
60
|
+
58,ModuleDict,
|
|
61
|
+
59,ModuleList,
|
|
62
|
+
60,PairwiseDistance,
|
|
63
|
+
61,Parameter,
|
|
64
|
+
62,ParameterDict,
|
|
65
|
+
63,ParameterList,
|
|
66
|
+
64,PixelShuffle,
|
|
67
|
+
65,RNN,#f1e2cc
|
|
68
|
+
66,RNNBase,#f1e2cc
|
|
69
|
+
67,RNNCell,#f1e2cc
|
|
70
|
+
68,RNNCellBase,#f1e2cc
|
|
71
|
+
69,ReflectionPad1d,#cccccc
|
|
72
|
+
70,ReflectionPad2d,#cccccc
|
|
73
|
+
71,ReplicationPad1d,#cccccc
|
|
74
|
+
72,ReplicationPad2d,#cccccc
|
|
75
|
+
73,ReplicationPad3d,#cccccc
|
|
76
|
+
74,Sequential,
|
|
77
|
+
75,SyncBatchNorm,
|
|
78
|
+
76,Transformer,#f4cae4
|
|
79
|
+
77,TransformerDecoder,#f4cae4
|
|
80
|
+
78,TransformerDecoderLayer,#f4cae4
|
|
81
|
+
79,TransformerEncoder,#f4cae4
|
|
82
|
+
80,TransformerEncoderLayer,#f4cae4
|
|
83
|
+
81,Unfold,
|
|
84
|
+
82,Upsample,
|
|
85
|
+
83,UpsamplingBilinear2d,
|
|
86
|
+
84,UpsamplingNearest2d,
|
|
87
|
+
85,ZeroPad2d,#cccccc
|
|
88
|
+
,,
|
|
89
|
+
,,
|
|
90
|
+
,,
|
|
91
|
+
,,
|
|
92
|
+
,,
|
|
93
|
+
,,
|
|
94
|
+
,,
|
|
95
|
+
,,
|
|
96
|
+
,,
|
|
97
|
+
,,
|
|
98
|
+
,,
|
|
99
|
+
,,
|
|
100
|
+
,,
|
|
101
|
+
,,
|
|
102
|
+
,,
|
|
103
|
+
,,
|
|
104
|
+
,,
|
|
105
|
+
,,
|
|
106
|
+
,,
|
|
107
|
+
,,
|
|
108
|
+
,,
|
|
109
|
+
,,
|
|
110
|
+
,,
|
|
111
|
+
,,
|
|
112
|
+
,,
|
|
113
|
+
,,
|
|
114
|
+
,,
|
|
115
|
+
,,
|
|
116
|
+
,,
|
|
117
|
+
,,
|