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.
Files changed (171) hide show
  1. aimodelshare/README.md +26 -0
  2. aimodelshare/__init__.py +100 -0
  3. aimodelshare/aimsonnx.py +2381 -0
  4. aimodelshare/api.py +836 -0
  5. aimodelshare/auth.py +163 -0
  6. aimodelshare/aws.py +511 -0
  7. aimodelshare/aws_client.py +173 -0
  8. aimodelshare/base_image.py +154 -0
  9. aimodelshare/bucketpolicy.py +106 -0
  10. aimodelshare/color_mappings/color_mapping_keras.csv +121 -0
  11. aimodelshare/color_mappings/color_mapping_pytorch.csv +117 -0
  12. aimodelshare/containerisation.py +244 -0
  13. aimodelshare/containerization.py +712 -0
  14. aimodelshare/containerization_templates/Dockerfile.txt +8 -0
  15. aimodelshare/containerization_templates/Dockerfile_PySpark.txt +23 -0
  16. aimodelshare/containerization_templates/buildspec.txt +14 -0
  17. aimodelshare/containerization_templates/lambda_function.txt +40 -0
  18. aimodelshare/custom_approach/__init__.py +1 -0
  19. aimodelshare/custom_approach/lambda_function.py +17 -0
  20. aimodelshare/custom_eval_metrics.py +103 -0
  21. aimodelshare/data_sharing/__init__.py +0 -0
  22. aimodelshare/data_sharing/data_sharing_templates/Dockerfile.txt +3 -0
  23. aimodelshare/data_sharing/data_sharing_templates/__init__.py +1 -0
  24. aimodelshare/data_sharing/data_sharing_templates/buildspec.txt +15 -0
  25. aimodelshare/data_sharing/data_sharing_templates/codebuild_policies.txt +129 -0
  26. aimodelshare/data_sharing/data_sharing_templates/codebuild_trust_relationship.txt +12 -0
  27. aimodelshare/data_sharing/download_data.py +620 -0
  28. aimodelshare/data_sharing/share_data.py +373 -0
  29. aimodelshare/data_sharing/utils.py +8 -0
  30. aimodelshare/deploy_custom_lambda.py +246 -0
  31. aimodelshare/documentation/Makefile +20 -0
  32. aimodelshare/documentation/karma_sphinx_theme/__init__.py +28 -0
  33. aimodelshare/documentation/karma_sphinx_theme/_version.py +2 -0
  34. aimodelshare/documentation/karma_sphinx_theme/breadcrumbs.html +70 -0
  35. aimodelshare/documentation/karma_sphinx_theme/layout.html +172 -0
  36. aimodelshare/documentation/karma_sphinx_theme/search.html +50 -0
  37. aimodelshare/documentation/karma_sphinx_theme/searchbox.html +14 -0
  38. aimodelshare/documentation/karma_sphinx_theme/static/css/custom.css +2 -0
  39. aimodelshare/documentation/karma_sphinx_theme/static/css/custom.css.map +1 -0
  40. aimodelshare/documentation/karma_sphinx_theme/static/css/theme.css +2751 -0
  41. aimodelshare/documentation/karma_sphinx_theme/static/css/theme.css.map +1 -0
  42. aimodelshare/documentation/karma_sphinx_theme/static/css/theme.min.css +2 -0
  43. aimodelshare/documentation/karma_sphinx_theme/static/css/theme.min.css.map +1 -0
  44. aimodelshare/documentation/karma_sphinx_theme/static/font/fontello.eot +0 -0
  45. aimodelshare/documentation/karma_sphinx_theme/static/font/fontello.svg +32 -0
  46. aimodelshare/documentation/karma_sphinx_theme/static/font/fontello.ttf +0 -0
  47. aimodelshare/documentation/karma_sphinx_theme/static/font/fontello.woff +0 -0
  48. aimodelshare/documentation/karma_sphinx_theme/static/font/fontello.woff2 +0 -0
  49. aimodelshare/documentation/karma_sphinx_theme/static/js/theme.js +68 -0
  50. aimodelshare/documentation/karma_sphinx_theme/theme.conf +9 -0
  51. aimodelshare/documentation/make.bat +35 -0
  52. aimodelshare/documentation/requirements.txt +2 -0
  53. aimodelshare/documentation/source/about.rst +18 -0
  54. aimodelshare/documentation/source/advanced_features.rst +137 -0
  55. aimodelshare/documentation/source/competition.rst +218 -0
  56. aimodelshare/documentation/source/conf.py +58 -0
  57. aimodelshare/documentation/source/create_credentials.rst +86 -0
  58. aimodelshare/documentation/source/example_notebooks.rst +132 -0
  59. aimodelshare/documentation/source/functions.rst +151 -0
  60. aimodelshare/documentation/source/gettingstarted.rst +390 -0
  61. aimodelshare/documentation/source/images/creds1.png +0 -0
  62. aimodelshare/documentation/source/images/creds2.png +0 -0
  63. aimodelshare/documentation/source/images/creds3.png +0 -0
  64. aimodelshare/documentation/source/images/creds4.png +0 -0
  65. aimodelshare/documentation/source/images/creds5.png +0 -0
  66. aimodelshare/documentation/source/images/creds_file_example.png +0 -0
  67. aimodelshare/documentation/source/images/predict_tab.png +0 -0
  68. aimodelshare/documentation/source/index.rst +110 -0
  69. aimodelshare/documentation/source/modelplayground.rst +132 -0
  70. aimodelshare/exceptions.py +11 -0
  71. aimodelshare/generatemodelapi.py +1270 -0
  72. aimodelshare/iam/codebuild_policy.txt +129 -0
  73. aimodelshare/iam/codebuild_trust_relationship.txt +12 -0
  74. aimodelshare/iam/lambda_policy.txt +15 -0
  75. aimodelshare/iam/lambda_trust_relationship.txt +12 -0
  76. aimodelshare/json_templates/__init__.py +1 -0
  77. aimodelshare/json_templates/api_json.txt +155 -0
  78. aimodelshare/json_templates/auth/policy.txt +1 -0
  79. aimodelshare/json_templates/auth/role.txt +1 -0
  80. aimodelshare/json_templates/eval/policy.txt +1 -0
  81. aimodelshare/json_templates/eval/role.txt +1 -0
  82. aimodelshare/json_templates/function/policy.txt +1 -0
  83. aimodelshare/json_templates/function/role.txt +1 -0
  84. aimodelshare/json_templates/integration_response.txt +5 -0
  85. aimodelshare/json_templates/lambda_policy_1.txt +15 -0
  86. aimodelshare/json_templates/lambda_policy_2.txt +8 -0
  87. aimodelshare/json_templates/lambda_role_1.txt +12 -0
  88. aimodelshare/json_templates/lambda_role_2.txt +16 -0
  89. aimodelshare/leaderboard.py +174 -0
  90. aimodelshare/main/1.txt +132 -0
  91. aimodelshare/main/1B.txt +112 -0
  92. aimodelshare/main/2.txt +153 -0
  93. aimodelshare/main/3.txt +134 -0
  94. aimodelshare/main/4.txt +128 -0
  95. aimodelshare/main/5.txt +109 -0
  96. aimodelshare/main/6.txt +105 -0
  97. aimodelshare/main/7.txt +144 -0
  98. aimodelshare/main/8.txt +142 -0
  99. aimodelshare/main/__init__.py +1 -0
  100. aimodelshare/main/authorization.txt +275 -0
  101. aimodelshare/main/eval_classification.txt +79 -0
  102. aimodelshare/main/eval_lambda.txt +1709 -0
  103. aimodelshare/main/eval_regression.txt +80 -0
  104. aimodelshare/main/lambda_function.txt +8 -0
  105. aimodelshare/main/nst.txt +149 -0
  106. aimodelshare/model.py +1543 -0
  107. aimodelshare/modeluser.py +215 -0
  108. aimodelshare/moral_compass/README.md +408 -0
  109. aimodelshare/moral_compass/__init__.py +65 -0
  110. aimodelshare/moral_compass/_version.py +3 -0
  111. aimodelshare/moral_compass/api_client.py +601 -0
  112. aimodelshare/moral_compass/apps/__init__.py +69 -0
  113. aimodelshare/moral_compass/apps/ai_consequences.py +540 -0
  114. aimodelshare/moral_compass/apps/bias_detective.py +714 -0
  115. aimodelshare/moral_compass/apps/ethical_revelation.py +898 -0
  116. aimodelshare/moral_compass/apps/fairness_fixer.py +889 -0
  117. aimodelshare/moral_compass/apps/judge.py +888 -0
  118. aimodelshare/moral_compass/apps/justice_equity_upgrade.py +853 -0
  119. aimodelshare/moral_compass/apps/mc_integration_helpers.py +820 -0
  120. aimodelshare/moral_compass/apps/model_building_game.py +1104 -0
  121. aimodelshare/moral_compass/apps/model_building_game_beginner.py +687 -0
  122. aimodelshare/moral_compass/apps/moral_compass_challenge.py +858 -0
  123. aimodelshare/moral_compass/apps/session_auth.py +254 -0
  124. aimodelshare/moral_compass/apps/shared_activity_styles.css +349 -0
  125. aimodelshare/moral_compass/apps/tutorial.py +481 -0
  126. aimodelshare/moral_compass/apps/what_is_ai.py +853 -0
  127. aimodelshare/moral_compass/challenge.py +365 -0
  128. aimodelshare/moral_compass/config.py +187 -0
  129. aimodelshare/placeholders/model.onnx +0 -0
  130. aimodelshare/placeholders/preprocessor.zip +0 -0
  131. aimodelshare/playground.py +1968 -0
  132. aimodelshare/postprocessormodules.py +157 -0
  133. aimodelshare/preprocessormodules.py +373 -0
  134. aimodelshare/pyspark/1.txt +195 -0
  135. aimodelshare/pyspark/1B.txt +181 -0
  136. aimodelshare/pyspark/2.txt +220 -0
  137. aimodelshare/pyspark/3.txt +204 -0
  138. aimodelshare/pyspark/4.txt +187 -0
  139. aimodelshare/pyspark/5.txt +178 -0
  140. aimodelshare/pyspark/6.txt +174 -0
  141. aimodelshare/pyspark/7.txt +211 -0
  142. aimodelshare/pyspark/8.txt +206 -0
  143. aimodelshare/pyspark/__init__.py +1 -0
  144. aimodelshare/pyspark/authorization.txt +258 -0
  145. aimodelshare/pyspark/eval_classification.txt +79 -0
  146. aimodelshare/pyspark/eval_lambda.txt +1441 -0
  147. aimodelshare/pyspark/eval_regression.txt +80 -0
  148. aimodelshare/pyspark/lambda_function.txt +8 -0
  149. aimodelshare/pyspark/nst.txt +213 -0
  150. aimodelshare/python/my_preprocessor.py +58 -0
  151. aimodelshare/readme.md +26 -0
  152. aimodelshare/reproducibility.py +181 -0
  153. aimodelshare/sam/Dockerfile.txt +8 -0
  154. aimodelshare/sam/Dockerfile_PySpark.txt +24 -0
  155. aimodelshare/sam/__init__.py +1 -0
  156. aimodelshare/sam/buildspec.txt +11 -0
  157. aimodelshare/sam/codebuild_policies.txt +129 -0
  158. aimodelshare/sam/codebuild_trust_relationship.txt +12 -0
  159. aimodelshare/sam/codepipeline_policies.txt +173 -0
  160. aimodelshare/sam/codepipeline_trust_relationship.txt +12 -0
  161. aimodelshare/sam/spark-class.txt +2 -0
  162. aimodelshare/sam/template.txt +54 -0
  163. aimodelshare/tools.py +103 -0
  164. aimodelshare/utils/__init__.py +78 -0
  165. aimodelshare/utils/optional_deps.py +38 -0
  166. aimodelshare/utils.py +57 -0
  167. aimodelshare-0.3.7.dist-info/METADATA +298 -0
  168. aimodelshare-0.3.7.dist-info/RECORD +171 -0
  169. aimodelshare-0.3.7.dist-info/WHEEL +5 -0
  170. aimodelshare-0.3.7.dist-info/licenses/LICENSE +5 -0
  171. aimodelshare-0.3.7.dist-info/top_level.txt +1 -0
@@ -0,0 +1,129 @@
1
+ {
2
+ "Version": "2012-10-17",
3
+ "Statement": [
4
+ {
5
+ "Effect": "Allow",
6
+ "Resource": "*",
7
+ "Action": [
8
+ "logs:CreateLogGroup",
9
+ "logs:CreateLogStream",
10
+ "logs:PutLogEvents"
11
+ ]
12
+ },
13
+ {
14
+ "Effect": "Allow",
15
+ "Resource": "*",
16
+ "Action": [
17
+ "s3:PutObject",
18
+ "s3:GetObject",
19
+ "s3:GetObjectVersion",
20
+ "s3:GetBucketAcl",
21
+ "s3:GetBucketLocation"
22
+ ]
23
+ },
24
+ {
25
+ "Effect": "Allow",
26
+ "Action": [
27
+ "codebuild:CreateReportGroup",
28
+ "codebuild:CreateReport",
29
+ "codebuild:UpdateReport",
30
+ "codebuild:BatchPutTestCases",
31
+ "codebuild:BatchPutCodeCoverages"
32
+ ],
33
+ "Resource": "*"
34
+ },
35
+ {
36
+ "Effect": "Allow",
37
+ "Action": [
38
+ "ecr:*",
39
+ "cloudtrail:LookupEvents"
40
+ ],
41
+ "Resource": "*"
42
+ },
43
+ {
44
+ "Effect": "Allow",
45
+ "Action": [
46
+ "iam:CreateServiceLinkedRole"
47
+ ],
48
+ "Resource": "*",
49
+ "Condition": {
50
+ "StringEquals": {
51
+ "iam:AWSServiceName": [
52
+ "replication.ecr.amazonaws.com"
53
+ ]
54
+ }
55
+ }
56
+ },
57
+ {
58
+ "Effect": "Allow",
59
+ "Action": [
60
+ "cloudformation:*"
61
+ ],
62
+ "Resource": "*"
63
+ },
64
+ {
65
+ "Effect": "Allow",
66
+ "Action": [
67
+ "cloudformation:DescribeStacks",
68
+ "cloudformation:ListStackResources",
69
+ "cloudwatch:ListMetrics",
70
+ "cloudwatch:GetMetricData",
71
+ "ec2:DescribeSecurityGroups",
72
+ "ec2:DescribeSubnets",
73
+ "ec2:DescribeVpcs",
74
+ "kms:ListAliases",
75
+ "iam:GetPolicy",
76
+ "iam:GetPolicyVersion",
77
+ "iam:GetRole",
78
+ "iam:GetRolePolicy",
79
+ "iam:ListAttachedRolePolicies",
80
+ "iam:ListRolePolicies",
81
+ "iam:ListRoles",
82
+ "lambda:*",
83
+ "logs:DescribeLogGroups",
84
+ "states:DescribeStateMachine",
85
+ "states:ListStateMachines",
86
+ "tag:GetResources",
87
+ "xray:GetTraceSummaries",
88
+ "xray:BatchGetTraces"
89
+ ],
90
+ "Resource": "*"
91
+ },
92
+ {
93
+ "Effect": "Allow",
94
+ "Action": "iam:PassRole",
95
+ "Resource": "*",
96
+ "Condition": {
97
+ "StringEquals": {
98
+ "iam:PassedToService": "lambda.amazonaws.com"
99
+ }
100
+ }
101
+ },
102
+ {
103
+ "Effect": "Allow",
104
+ "Action": [
105
+ "logs:DescribeLogStreams",
106
+ "logs:GetLogEvents",
107
+ "logs:FilterLogEvents"
108
+ ],
109
+ "Resource": "arn:aws:logs:*:*:log-group:/aws/lambda/*"
110
+ },
111
+ {
112
+ "Effect": "Allow",
113
+ "Action": [
114
+ "iam:*",
115
+ "organizations:DescribeAccount",
116
+ "organizations:DescribeOrganization",
117
+ "organizations:DescribeOrganizationalUnit",
118
+ "organizations:DescribePolicy",
119
+ "organizations:ListChildren",
120
+ "organizations:ListParents",
121
+ "organizations:ListPoliciesForTarget",
122
+ "organizations:ListRoots",
123
+ "organizations:ListPolicies",
124
+ "organizations:ListTargetsForPolicy"
125
+ ],
126
+ "Resource": "*"
127
+ }
128
+ ]
129
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "Version": "2012-10-17",
3
+ "Statement": [
4
+ {
5
+ "Effect": "Allow",
6
+ "Principal": {
7
+ "Service": "codebuild.amazonaws.com"
8
+ },
9
+ "Action": "sts:AssumeRole"
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,173 @@
1
+ {
2
+ "Version": "2012-10-17",
3
+ "Statement": [
4
+ {
5
+ "Action": [
6
+ "iam:PassRole"
7
+ ],
8
+ "Resource": "*",
9
+ "Effect": "Allow",
10
+ "Condition": {
11
+ "StringEqualsIfExists": {
12
+ "iam:PassedToService": [
13
+ "cloudformation.amazonaws.com",
14
+ "elasticbeanstalk.amazonaws.com",
15
+ "ec2.amazonaws.com",
16
+ "ecs-tasks.amazonaws.com"
17
+ ]
18
+ }
19
+ }
20
+ },
21
+ {
22
+ "Action": [
23
+ "codecommit:CancelUploadArchive",
24
+ "codecommit:GetBranch",
25
+ "codecommit:GetCommit",
26
+ "codecommit:GetRepository",
27
+ "codecommit:GetUploadArchiveStatus",
28
+ "codecommit:UploadArchive"
29
+ ],
30
+ "Resource": "*",
31
+ "Effect": "Allow"
32
+ },
33
+ {
34
+ "Action": [
35
+ "codedeploy:CreateDeployment",
36
+ "codedeploy:GetApplication",
37
+ "codedeploy:GetApplicationRevision",
38
+ "codedeploy:GetDeployment",
39
+ "codedeploy:GetDeploymentConfig",
40
+ "codedeploy:RegisterApplicationRevision"
41
+ ],
42
+ "Resource": "*",
43
+ "Effect": "Allow"
44
+ },
45
+ {
46
+ "Action": [
47
+ "codestar-connections:UseConnection"
48
+ ],
49
+ "Resource": "*",
50
+ "Effect": "Allow"
51
+ },
52
+ {
53
+ "Action": [
54
+ "elasticbeanstalk:*",
55
+ "ec2:*",
56
+ "elasticloadbalancing:*",
57
+ "autoscaling:*",
58
+ "cloudwatch:*",
59
+ "s3:*",
60
+ "sns:*",
61
+ "cloudformation:*",
62
+ "rds:*",
63
+ "sqs:*",
64
+ "ecs:*"
65
+ ],
66
+ "Resource": "*",
67
+ "Effect": "Allow"
68
+ },
69
+ {
70
+ "Action": [
71
+ "lambda:InvokeFunction",
72
+ "lambda:ListFunctions"
73
+ ],
74
+ "Resource": "*",
75
+ "Effect": "Allow"
76
+ },
77
+ {
78
+ "Action": [
79
+ "opsworks:CreateDeployment",
80
+ "opsworks:DescribeApps",
81
+ "opsworks:DescribeCommands",
82
+ "opsworks:DescribeDeployments",
83
+ "opsworks:DescribeInstances",
84
+ "opsworks:DescribeStacks",
85
+ "opsworks:UpdateApp",
86
+ "opsworks:UpdateStack"
87
+ ],
88
+ "Resource": "*",
89
+ "Effect": "Allow"
90
+ },
91
+ {
92
+ "Action": [
93
+ "cloudformation:CreateStack",
94
+ "cloudformation:DeleteStack",
95
+ "cloudformation:DescribeStacks",
96
+ "cloudformation:UpdateStack",
97
+ "cloudformation:CreateChangeSet",
98
+ "cloudformation:DeleteChangeSet",
99
+ "cloudformation:DescribeChangeSet",
100
+ "cloudformation:ExecuteChangeSet",
101
+ "cloudformation:SetStackPolicy",
102
+ "cloudformation:ValidateTemplate"
103
+ ],
104
+ "Resource": "*",
105
+ "Effect": "Allow"
106
+ },
107
+ {
108
+ "Action": [
109
+ "codebuild:BatchGetBuilds",
110
+ "codebuild:StartBuild",
111
+ "codebuild:BatchGetBuildBatches",
112
+ "codebuild:StartBuildBatch"
113
+ ],
114
+ "Resource": "*",
115
+ "Effect": "Allow"
116
+ },
117
+ {
118
+ "Effect": "Allow",
119
+ "Action": [
120
+ "devicefarm:ListProjects",
121
+ "devicefarm:ListDevicePools",
122
+ "devicefarm:GetRun",
123
+ "devicefarm:GetUpload",
124
+ "devicefarm:CreateUpload",
125
+ "devicefarm:ScheduleRun"
126
+ ],
127
+ "Resource": "*"
128
+ },
129
+ {
130
+ "Effect": "Allow",
131
+ "Action": [
132
+ "servicecatalog:ListProvisioningArtifacts",
133
+ "servicecatalog:CreateProvisioningArtifact",
134
+ "servicecatalog:DescribeProvisioningArtifact",
135
+ "servicecatalog:DeleteProvisioningArtifact",
136
+ "servicecatalog:UpdateProduct"
137
+ ],
138
+ "Resource": "*"
139
+ },
140
+ {
141
+ "Effect": "Allow",
142
+ "Action": [
143
+ "cloudformation:ValidateTemplate"
144
+ ],
145
+ "Resource": "*"
146
+ },
147
+ {
148
+ "Effect": "Allow",
149
+ "Action": [
150
+ "ecr:DescribeImages"
151
+ ],
152
+ "Resource": "*"
153
+ },
154
+ {
155
+ "Effect": "Allow",
156
+ "Action": [
157
+ "states:DescribeExecution",
158
+ "states:DescribeStateMachine",
159
+ "states:StartExecution"
160
+ ],
161
+ "Resource": "*"
162
+ },
163
+ {
164
+ "Effect": "Allow",
165
+ "Action": [
166
+ "appconfig:StartDeployment",
167
+ "appconfig:StopDeployment",
168
+ "appconfig:GetDeployment"
169
+ ],
170
+ "Resource": "*"
171
+ }
172
+ ]
173
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "Version": "2012-10-17",
3
+ "Statement": [
4
+ {
5
+ "Effect": "Allow",
6
+ "Principal": {
7
+ "Service": "codepipeline.amazonaws.com"
8
+ },
9
+ "Action": "sts:AssumeRole"
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bash
2
+ exec /usr/lib/jvm/java-1.8.0-openjdk*/jre/bin/java -cp /var/lang/lib/python$python_version/site-packages/pyspark/conf/:/var/lang/lib/python$python_version/site-packages/pyspark/jars/* -Xmx1g "$var"
@@ -0,0 +1,54 @@
1
+ AWSTemplateFormatVersion: '2010-09-09'
2
+ Transform: AWS::Serverless-2016-10-31
3
+
4
+ Resources:
5
+
6
+ Role:
7
+ Type: AWS::IAM::Role
8
+ Properties:
9
+ AssumeRolePolicyDocument:
10
+ Version: "2012-10-17"
11
+ Statement:
12
+ - Effect: Allow
13
+ Principal:
14
+ Service:
15
+ - lambda.amazonaws.com
16
+ Action:
17
+ - 'sts:AssumeRole'
18
+ RoleName: $role_name
19
+
20
+ Policy:
21
+ Type: AWS::IAM::Policy
22
+ DependsOn: Role
23
+ Properties:
24
+ PolicyDocument: {
25
+ "Version": "2012-10-17",
26
+ "Statement": [
27
+ {
28
+ "Effect": "Allow",
29
+ "Action": "s3:*",
30
+ "Resource": "*"
31
+ },
32
+ {
33
+ "Action": "logs:*",
34
+ "Resource": "*",
35
+ "Effect": "Allow"
36
+ }
37
+ ]
38
+ }
39
+ PolicyName: $policy_name
40
+ Roles: [$role_name]
41
+
42
+ Lambda:
43
+ Type: AWS::Serverless::Function
44
+ DependsOn: Role
45
+ Metadata:
46
+ Dockerfile: Dockerfile
47
+ DockerContext: ./app
48
+ DockerTag: $image_tag
49
+ Properties:
50
+ PackageType: Image
51
+ FunctionName: $function_name
52
+ MemorySize: $memory_size
53
+ Timeout: $timeout
54
+ Role: !GetAtt Role.Arn
aimodelshare/tools.py ADDED
@@ -0,0 +1,103 @@
1
+ import json
2
+ import pydot
3
+ import argparse
4
+ import datetime
5
+ import os
6
+
7
+ from onnx import NodeProto
8
+ from typing import Callable
9
+ from collections import defaultdict
10
+
11
+
12
+ OP_STYLE = {"shape": "box", "color": "#252c36", "fontcolor": "#252c36"}
13
+ BLOB_STYLE = {"shape": "octagon", "color": "#ff4971", "fontcolor": "#ff4971"}
14
+
15
+ _NodeProducer = Callable[[NodeProto, int], pydot.Node]
16
+
17
+
18
+ def _escape_label(name):
19
+
20
+ return json.dumps(name)
21
+
22
+
23
+ def _form_and_sanitize_docstring(s):
24
+ url = "javascript:alert("
25
+ url += _escape_label(s).replace('"', "'").replace("<", "").replace(">", "")
26
+ url += ")"
27
+ return url
28
+
29
+
30
+ def GetOpNodeProducer(**kwargs):
31
+ def ReallyGetOpNode(op, op_id):
32
+ if op.name:
33
+ node_name = "%s/%s" % (op.op_type, op.name)
34
+ else:
35
+ node_name = "%s" % (op.op_type)
36
+ node = pydot.Node(node_name, **kwargs)
37
+
38
+ return node
39
+
40
+ return ReallyGetOpNode
41
+
42
+
43
+ def get_model_graph(graph, name=None, flow="LR"):
44
+ node_producer = GetOpNodeProducer(**OP_STYLE)
45
+
46
+ pydot_graph = pydot.Dot(name, rankdir=flow)
47
+ pydot_node_counts = defaultdict(int)
48
+ pydot_nodes = {}
49
+
50
+ for op_id, op in enumerate(graph.node):
51
+ op_node = node_producer(op, op_id)
52
+ pydot_graph.add_node(op_node)
53
+
54
+ for input_name in op.input:
55
+ if input_name not in pydot_nodes:
56
+ input_node = pydot.Node(
57
+ _escape_label(input_name + str(pydot_node_counts[input_name])),
58
+ label=_escape_label(input_name),
59
+ **BLOB_STYLE
60
+ )
61
+ pydot_nodes[input_name] = input_node
62
+ else:
63
+ input_node = pydot_nodes[input_name]
64
+ pydot_graph.add_node(input_node)
65
+ pydot_graph.add_edge(pydot.Edge(input_node, op_node))
66
+
67
+ for output_name in op.output:
68
+ if output_name in pydot_nodes:
69
+ pydot_node_counts[output_name] += 1
70
+ output_node = pydot.Node(
71
+ _escape_label(output_name + str(pydot_node_counts[output_name])),
72
+ label=_escape_label(output_name),
73
+ **BLOB_STYLE
74
+ )
75
+ pydot_nodes[output_name] = output_node
76
+ pydot_graph.add_node(output_node)
77
+ pydot_graph.add_edge(pydot.Edge(op_node, output_node))
78
+
79
+ return pydot_graph
80
+
81
+ def form_timestamp(ts):
82
+ st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
83
+ st2 = st.replace(" ","_")
84
+ st3 = st2.replace(":","_")
85
+ return st3
86
+
87
+ #Pandas training data pointer (currently for data updates only)
88
+ def extract_varnames_fromtrainingdata(trainingdata="default"):
89
+ import pandas as pd
90
+ import numpy as np
91
+ if isinstance(trainingdata, pd.DataFrame):
92
+ variabletypes=list(trainingdata.dtypes.values.astype(str)) # always use pandas dtypes
93
+ variablecolumns=list(trainingdata.columns)
94
+ else:
95
+ variabletypes=None
96
+ variablecolumns=None
97
+ return [variabletypes,variablecolumns]
98
+
99
+ def _get_extension_from_filepath(Filepath):
100
+ Filename = os.path.basename(Filepath)
101
+ file_name, file_extension = os.path.splitext(Filename)
102
+ return file_extension
103
+
@@ -0,0 +1,78 @@
1
+ """Utility modules for aimodelshare."""
2
+ import os
3
+ import sys
4
+ import shutil
5
+ import tempfile
6
+ import functools
7
+ import warnings
8
+ from typing import Type
9
+
10
+ from .optional_deps import check_optional
11
+
12
+
13
+ def delete_files_from_temp_dir(temp_dir_file_deletion_list):
14
+ temp_dir = tempfile.gettempdir()
15
+ for file_name in temp_dir_file_deletion_list:
16
+ file_path = os.path.join(temp_dir, file_name)
17
+ if os.path.exists(file_path):
18
+ os.remove(file_path)
19
+
20
+
21
+ def delete_folder(folder_path):
22
+ if os.path.exists(folder_path):
23
+ shutil.rmtree(folder_path)
24
+
25
+
26
+ def make_folder(folder_path):
27
+ os.makedirs(folder_path, exist_ok=True)
28
+
29
+
30
+ class HiddenPrints:
31
+ """Context manager that suppresses stdout and stderr (used for silencing noisy outputs)."""
32
+ def __enter__(self):
33
+ self._original_stdout = sys.stdout
34
+ self._original_stderr = sys.stderr
35
+ self._devnull_stdout = open(os.devnull, 'w')
36
+ self._devnull_stderr = open(os.devnull, 'w')
37
+ sys.stdout = self._devnull_stdout
38
+ sys.stderr = self._devnull_stderr
39
+ return self
40
+
41
+ def __exit__(self, exc_type, exc_val, exc_tb):
42
+ sys.stdout = self._original_stdout
43
+ sys.stderr = self._original_stderr
44
+ self._devnull_stdout.close()
45
+ self._devnull_stderr.close()
46
+
47
+
48
+ def ignore_warning(warning: Type[Warning]):
49
+ """
50
+ Ignore a given warning occurring during method execution.
51
+
52
+ Args:
53
+ warning (Warning): warning type to ignore.
54
+
55
+ Returns:
56
+ the inner function
57
+ """
58
+
59
+ def inner(func):
60
+ @functools.wraps(func)
61
+ def wrapper(*args, **kwargs):
62
+ with warnings.catch_warnings():
63
+ warnings.filterwarnings("ignore", category=warning)
64
+ return func(*args, **kwargs)
65
+
66
+ return wrapper
67
+
68
+ return inner
69
+
70
+
71
+ __all__ = [
72
+ "check_optional",
73
+ "HiddenPrints",
74
+ "ignore_warning",
75
+ "delete_files_from_temp_dir",
76
+ "delete_folder",
77
+ "make_folder",
78
+ ]
@@ -0,0 +1,38 @@
1
+ """Optional dependency checking utilities."""
2
+ import os
3
+ import importlib.util
4
+ import warnings
5
+
6
+ _DEF_SUPPRESS_ENV = "AIMODELSHARE_SUPPRESS_OPTIONAL_WARNINGS"
7
+
8
+
9
+ def check_optional(name: str, feature_label: str, suppress_env: str = _DEF_SUPPRESS_ENV) -> bool:
10
+ """Check if an optional dependency is available.
11
+
12
+ Print a single warning (via warnings) if missing and suppression env var is not set.
13
+ Returns True if available, False otherwise.
14
+
15
+ Parameters
16
+ ----------
17
+ name : str
18
+ The name of the module to check (e.g., 'xgboost', 'pyspark')
19
+ feature_label : str
20
+ A human-readable label for the feature that requires this dependency
21
+ suppress_env : str, optional
22
+ Environment variable name to check for suppression (default: AIMODELSHARE_SUPPRESS_OPTIONAL_WARNINGS)
23
+
24
+ Returns
25
+ -------
26
+ bool
27
+ True if the module is available, False otherwise
28
+ """
29
+ spec = importlib.util.find_spec(name)
30
+ if spec is None:
31
+ if not os.environ.get(suppress_env):
32
+ warnings.warn(
33
+ f"{feature_label} support unavailable. Install `{name}` to enable.",
34
+ category=UserWarning,
35
+ stacklevel=2,
36
+ )
37
+ return False
38
+ return True
aimodelshare/utils.py ADDED
@@ -0,0 +1,57 @@
1
+ import os
2
+ import sys
3
+ import shutil
4
+ import tempfile
5
+ import functools
6
+ import warnings
7
+ from typing import Type
8
+
9
+
10
+ def delete_files_from_temp_dir(temp_dir_file_deletion_list):
11
+ temp_dir = tempfile.gettempdir()
12
+ for file_name in temp_dir_file_deletion_list:
13
+ file_path = os.path.join(temp_dir, file_name)
14
+ if os.path.exists(file_path):
15
+ os.remove(file_path)
16
+
17
+
18
+ def delete_folder(folder_path):
19
+ if os.path.exists(folder_path):
20
+ shutil.rmtree(folder_path)
21
+
22
+
23
+ def make_folder(folder_path):
24
+ os.makedirs(folder_path, exist_ok=True)
25
+
26
+
27
+ class HiddenPrints:
28
+ def __enter__(self):
29
+ self._original_stdout = sys.stdout
30
+ sys.stdout = open(os.devnull, 'w')
31
+
32
+ def __exit__(self, exc_type, exc_val, exc_tb):
33
+ sys.stdout.close()
34
+ sys.stdout = self._original_stdout
35
+
36
+
37
+ def ignore_warning(warning: Type[Warning]):
38
+ """
39
+ Ignore a given warning occurring during method execution.
40
+
41
+ Args:
42
+ warning (Warning): warning type to ignore.
43
+
44
+ Returns:
45
+ the inner function
46
+ """
47
+
48
+ def inner(func):
49
+ @functools.wraps(func)
50
+ def wrapper(*args, **kwargs):
51
+ with warnings.catch_warnings():
52
+ warnings.filterwarnings("ignore", category=warning)
53
+ return func(*args, **kwargs)
54
+
55
+ return wrapper
56
+
57
+ return inner