Spaces:
Sleeping
Sleeping
qqubb
commited on
Commit
·
a635b88
1
Parent(s):
5be1f85
refactor code and initial UI
Browse files- __pycache__/compliance_analysis.cpython-310.pyc +0 -0
- __pycache__/utils.cpython-310.pyc +0 -0
- app.py +24 -0
- compliance_analysis.py +113 -261
- utils.py +107 -0
__pycache__/compliance_analysis.cpython-310.pyc
ADDED
Binary file (3.85 kB). View file
|
|
__pycache__/utils.cpython-310.pyc
ADDED
Binary file (2.27 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import yaml
|
3 |
+
from compliance_analysis import run_compliance_analysis_on_project
|
4 |
+
|
5 |
+
def process_files(files):
|
6 |
+
results = []
|
7 |
+
for file in files:
|
8 |
+
with open(file.name, 'r') as f:
|
9 |
+
content = f.read()
|
10 |
+
project_cc_yaml = yaml.safe_load(content)
|
11 |
+
msg = run_compliance_analysis_on_project(project_cc_yaml)
|
12 |
+
results.append(msg)
|
13 |
+
|
14 |
+
return results
|
15 |
+
|
16 |
+
# Gradio interface
|
17 |
+
with gr.Blocks() as demo:
|
18 |
+
file_input = gr.File(label="Upload Files", file_count="multiple")
|
19 |
+
output = gr.Textbox(label="Output", lines=10)
|
20 |
+
|
21 |
+
submit_button = gr.Button("Process Files")
|
22 |
+
submit_button.click(process_files, inputs=file_input, outputs=output)
|
23 |
+
|
24 |
+
demo.launch()
|
compliance_analysis.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
-
import os
|
2 |
-
import sys
|
3 |
import yaml
|
4 |
-
from
|
5 |
|
6 |
# Create some variables we will use throughout our analysis
|
7 |
|
@@ -27,310 +25,164 @@ project_variables = {
|
|
27 |
}
|
28 |
}
|
29 |
|
30 |
-
|
31 |
-
def create_list_of_files(folder_path):
|
32 |
-
for root, dirs, files in os.walk(folder_path):
|
33 |
-
for filename in files:
|
34 |
-
found_files.append(os.path.join(root, filename))
|
35 |
-
|
36 |
-
#Define a function that checks for a Project CC. Without this, there simply cannot be an analysis.
|
37 |
-
def check_for_project_cc(folder_path):
|
38 |
-
found_files = []
|
39 |
-
|
40 |
-
# Walk through the directory
|
41 |
-
for root, dirs, files in os.walk(folder_path):
|
42 |
-
for filename in files:
|
43 |
-
if filename.lower() == 'project_cc.yaml':
|
44 |
-
found_files.append(os.path.join(root, filename))
|
45 |
-
|
46 |
-
# Check the results
|
47 |
-
if len(found_files) == 0:
|
48 |
-
print(f"We did not find a Project CC in your folder. We cannot run a compliance analysis without a Project CC.")
|
49 |
-
sys.exit()
|
50 |
-
elif len(found_files) == 1:
|
51 |
-
print(f"We found exactly one Project CC in your folder. Great job!:")
|
52 |
-
print(f" - {found_files[0]}")
|
53 |
-
run_compliance_analysis(folder_path)
|
54 |
-
else:
|
55 |
-
print(f"Multiple Project CCs found:")
|
56 |
-
for file_path in found_files:
|
57 |
-
print(f" - {file_path}")
|
58 |
-
print("We found multiple Project CCs in your folder. There should only be one Project CC per project.")
|
59 |
-
|
60 |
-
def run_compliance_analysis(folder_path):
|
61 |
-
|
62 |
-
# Load the Project CC YAML file from the supplied folder. This will be our starting point.
|
63 |
-
with open(folder_path + 'project_cc.yaml', 'r') as file:
|
64 |
-
project_cc_yaml = yaml.safe_load(file)
|
65 |
|
66 |
# Determine project type (AI system vs. GPAI model) as well as operator type. We will use these for different things.
|
67 |
-
set_type(project_variables, project_cc_yaml)
|
68 |
set_operator_role_and_location(project_variables, project_cc_yaml)
|
69 |
set_eu_market_status(project_variables, project_cc_yaml)
|
70 |
|
71 |
# Check if the project is within scope of the Act. If it's not, the analysis is over.
|
72 |
if check_within_scope(project_cc_yaml):
|
73 |
-
|
74 |
else:
|
75 |
-
|
76 |
|
77 |
-
# Check for prohibited practices. If any exist, the analysis is over.
|
78 |
-
if check_prohibited(project_cc_yaml) == True:
|
79 |
-
|
80 |
-
|
81 |
-
else:
|
82 |
-
|
83 |
|
84 |
# If project is high-risk AI system, check that is has met all the requirements for such systems:
|
85 |
|
86 |
-
if high_risk_ai_system:
|
87 |
|
88 |
# Do this by examining the Project CC
|
89 |
|
90 |
for key, value in project_cc_yaml['risk_management_system']:
|
91 |
if not value:
|
92 |
-
|
93 |
for key, value in project_cc_yaml['technical_documentation']:
|
94 |
if not value:
|
95 |
-
|
96 |
for key, value in project_cc_yaml['record_keeping']:
|
97 |
if not value:
|
98 |
-
|
99 |
for key, value in project_cc_yaml['transparency_and_provision_of_information_to_deployers']:
|
100 |
if not value:
|
101 |
-
|
102 |
for key, value in project_cc_yaml['human_oversight']:
|
103 |
if not value:
|
104 |
-
|
105 |
for key, value in project_cc_yaml['accuracy_robustness_cybersecurity']:
|
106 |
if not value:
|
107 |
-
|
108 |
for key, value in project_cc_yaml['quality_management_system']:
|
109 |
if not value:
|
110 |
-
|
|
|
|
|
111 |
|
|
|
112 |
# Do this by examining any and all Data CCs too
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
-
for filename in os.listdir(folder_path):
|
115 |
-
# Check if the search word is in the filename
|
116 |
-
if "data_cc.md" in filename.lower():
|
117 |
-
|
118 |
-
# If it is, load the yaml
|
119 |
-
|
120 |
-
with open(folder_path + filename, 'r') as file:
|
121 |
-
data_cc_yaml = yaml.safe_load(file)
|
122 |
-
|
123 |
-
for key, value in data_cc_yaml['data_and_data_governance']:
|
124 |
-
if not value:
|
125 |
-
sys.exit(f"Because of the dataset represented by {filename}, this high-risk AI system fails the data and data governance requirements under Article 10.")
|
126 |
-
for key, value in data_cc_yaml['technical_documentation']:
|
127 |
-
if not value:
|
128 |
-
sys.exit(f"Because of the dataset represented by {filename}, this high-risk AI system fails the technical documentation requirements under Article 11.")
|
129 |
-
for key, value in data_cc_yaml['transparency_and_provision_of_information_to_deployers']:
|
130 |
-
if not value:
|
131 |
-
sys.exit(f"Because of the dataset represented by {filename}, this high-risk AI system fails the transparency requirements under Article 13.")
|
132 |
-
for key, value in data_cc_yaml['quality_management_system']:
|
133 |
-
if not value:
|
134 |
-
sys.exit(f"Because of the dataset represented by {filename}, this high-risk AI system fails the quality management requirements under Article 17.")
|
135 |
-
|
136 |
-
# Do this by examining any and all Model CCs too
|
137 |
-
|
138 |
-
for filename in os.listdir(folder_path):
|
139 |
-
# Check if the search word is in the filename
|
140 |
-
if "model_cc.md" in filename.lower():
|
141 |
-
|
142 |
-
# If it is, load the yaml
|
143 |
-
|
144 |
-
with open(folder_path + filename, 'r') as file:
|
145 |
-
model_cc_yaml = yaml.safe_load(file)
|
146 |
-
|
147 |
-
for key, value in model_cc_yaml['risk_management_system']:
|
148 |
-
if not value:
|
149 |
-
sys.exit(f"Because of the model represented by {filename}, this high-risk AI system fails the risk management requirements under Article 9.")
|
150 |
-
for key, value in data_cc_yaml['technical_documentation']:
|
151 |
-
if not value:
|
152 |
-
sys.exit(f"Because of the model represented by {filename}, this high-risk AI system fails the technical documentation requirements under Article 11.")
|
153 |
-
for key, value in data_cc_yaml['transparency_and_provision_of_information_to_deployers']:
|
154 |
-
if not value:
|
155 |
-
sys.exit(f"Because of the model represented by {filename}, this high-risk AI system fails the transparency requirements under Article 13.")
|
156 |
-
for key, value in data_cc_yaml['accuracy_robustness_cybersecurity']:
|
157 |
-
if not value:
|
158 |
-
sys.exit(f"Because of the model represented by {filename}, this high-risk AI system fails the quality management requirements under Article 15.")
|
159 |
-
for key, value in data_cc_yaml['quality_management_system']:
|
160 |
-
if not value:
|
161 |
-
sys.exit(f"Because of the model represented by {filename}, this high-risk AI system fails the quality management requirements under Article 17.")
|
162 |
-
|
163 |
-
# If the project is a GPAI model, check that is has met all the requirements for such systems:
|
164 |
-
|
165 |
-
if gpai_model:
|
166 |
|
167 |
-
#
|
168 |
|
169 |
-
|
170 |
-
if not value:
|
171 |
-
sys.exit("GPAI model fails the transparency requirements under Article 53.")
|
172 |
|
173 |
-
# Do this by examining
|
|
|
|
|
|
|
|
|
174 |
|
175 |
-
|
176 |
-
# Check if the search word is in the filename
|
177 |
-
if "data_cc.md" in filename.lower():
|
178 |
|
179 |
-
|
|
|
|
|
180 |
|
181 |
-
|
182 |
-
data_cc_yaml = yaml.safe_load(file)
|
183 |
|
184 |
-
|
185 |
-
|
186 |
-
sys.exit(f"Because of the dataset represented by {filename}, this GPAI fails the transparency requirements under Article 53.")
|
187 |
|
188 |
-
#
|
|
|
|
|
|
|
|
|
189 |
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
|
194 |
-
|
195 |
|
196 |
-
|
197 |
-
|
198 |
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
|
203 |
-
# If the project is a GPAI model with systematic risk, check that is has additionally met all the requirements for such systems:
|
204 |
|
205 |
-
if gpai_model_systematic_risk:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
|
207 |
-
# Do this by examining the Project CC
|
208 |
|
209 |
-
for key, value in project_cc_yaml['gpai_obligations_for_systemic_risk_models']:
|
210 |
-
if not value:
|
211 |
-
sys.exit("GPAI model with systematic risk fails the transparency requirements under Article 55.")
|
212 |
-
|
213 |
-
# Do this by examining any and all Model CCs too
|
214 |
-
|
215 |
-
for filename in os.listdir(folder_path):
|
216 |
-
# Check if the search word is in the filename
|
217 |
-
if "model_cc.md" in filename.lower():
|
218 |
-
|
219 |
-
# If it is, load the yaml
|
220 |
-
|
221 |
-
with open(folder_path + filename, 'r') as file:
|
222 |
-
model_cc_yaml = yaml.safe_load(file)
|
223 |
-
|
224 |
-
for key, value in model_cc_yaml['obligations_for_providers_of_gpai_models_with_systemic_risk']:
|
225 |
-
if not value:
|
226 |
-
sys.exit(f"Because of the model represented by {filename}, this GPAI model with systematic risk fails the transparency requirements under Article 55.")
|
227 |
-
|
228 |
-
def set_type(project_variables, project_cc_yaml):
|
229 |
-
ai_system = project_variables['ai_project_type']['ai_system']
|
230 |
-
gpai_model = project_variables['ai_project_type']['gpai_model']
|
231 |
-
if project_cc_yaml['ai_system']['ai_system']['value']:
|
232 |
-
ai_system = True
|
233 |
-
if project_cc_yaml['gpai_model']['gpai_model']['value']:
|
234 |
-
gpai_model = True
|
235 |
-
if ai_system and gpai_model:
|
236 |
-
sys.exit("Your project cannot be both an AI system and a GPAI model. Please revise your Project CC accordingly.")
|
237 |
-
if ai_system == True:
|
238 |
-
for key, value in project_cc_yaml['high_risk_ai_system']:
|
239 |
-
if value and sum(map(bool, [project_cc_yaml['high_risk_ai_system']['filter_exception_rights'],project_cc_yaml['high_risk_ai_system']['filter_exception_narrow'],project_cc_yaml['high_risk_ai_system']['filter_exception_human'],project_cc_yaml['high_risk_ai_system']['filter_exception_deviation'], project_cc_yaml['high_risk_ai_system']['filter_exception_prep']])) < 1:
|
240 |
-
high_risk_ai_system == True
|
241 |
-
if gpai_model == True:
|
242 |
-
if project_cc_yaml['gpai_model_systematic_risk']['evaluation'] or project_cc_yaml['gpai_model_systematic_risk']['flops']:
|
243 |
-
gpai_model_systematic_risk == True
|
244 |
-
|
245 |
-
def set_operator_role_and_location(project_variables, project_cc_yaml):
|
246 |
-
operators = 0
|
247 |
-
|
248 |
-
ai_system = project_variables['ai_project_type']['ai_system']
|
249 |
-
gpai_model = project_variables['ai_project_type']['gpai_model']
|
250 |
-
|
251 |
-
for var in project_variables['operator_role']:
|
252 |
-
if project_cc_yaml['operator_role'][f'{var}']['value']:
|
253 |
-
project_variables['operator_role'][f'{var}'] = True
|
254 |
-
operators += 1
|
255 |
-
|
256 |
-
if ai_system and gpai_model:
|
257 |
-
sys.exit("Your project cannot be both an AI system and a GPAI model. Please revise your Project CC accordingly.")
|
258 |
-
if operators != 1:
|
259 |
-
sys.exit("Please specify exactly one operator role.")
|
260 |
-
|
261 |
-
return project_variables
|
262 |
|
263 |
-
def set_eu_market_status(project_variables, project_cc_yaml):
|
264 |
-
|
265 |
-
if project_cc_yaml['eu_market_status']['placed_on_market']['value']:
|
266 |
-
project_variables['eu_market_status']["placed_on_market"] = True
|
267 |
-
if project_cc_yaml['eu_market_status']['put_into_service']['value']:
|
268 |
-
project_variables['eu_market_status']["put_into_service"] = True
|
269 |
-
|
270 |
-
if project_cc_yaml['operator_role']['output_used']['value']:
|
271 |
-
project_variables['operator_role']["output_used"] = True
|
272 |
-
|
273 |
-
return project_variables
|
274 |
-
|
275 |
-
def check_within_scope(project_cc):
|
276 |
-
if not check_excepted(project_cc):
|
277 |
-
if provider and ((ai_system and (placed_on_market or put_into_service)) or (gpai_model and placed_on_market)): # Article 2.1(a)
|
278 |
-
return True
|
279 |
-
if deployer and eu_located: # Article 2.1(b)
|
280 |
-
return True
|
281 |
-
if (provider or deployer) and (ai_system and eu_located and output_used): # Article 2.1(c)
|
282 |
-
return True
|
283 |
-
if (importer or distributor) and ai_system: # Article 2.1(d)
|
284 |
-
return True
|
285 |
-
if product_manufacturer and ai_system and (placed_on_market or put_into_service): # Article 2.1(e)
|
286 |
-
return True
|
287 |
-
else:
|
288 |
-
return False
|
289 |
-
|
290 |
-
def check_excepted(project_cc_yaml):
|
291 |
-
if project_cc_yaml['excepted']['scientific'] or project_cc_yaml['excepted']['pre_market'] or (ai_system and project_cc_yaml['excepted']['open_source_ai_system']) or (gpai_model and project_cc_yaml['excepted']['open_source_gpai_system']):
|
292 |
-
return True
|
293 |
-
else:
|
294 |
-
return False
|
295 |
-
|
296 |
-
def check_prohibited (project_cc_yaml):
|
297 |
-
if ai_system:
|
298 |
-
for key in project_cc_yaml['prohibited_practice']['ai_system']:
|
299 |
-
if key[value]:
|
300 |
-
print("You are engaged in a prohibited practice and thus the project is non-compliant.")
|
301 |
-
return True
|
302 |
-
if project_cc_yaml['prohibited_practice']['biometric']['categorization']:
|
303 |
-
print("You are engaged in a prohibited practice and thus the project is non-compliant.")
|
304 |
-
return True
|
305 |
-
if project_cc_yaml['prohibited_practice']['biometric']['real_time'] and sum(map(bool, [project_cc['prohibited_practice']['biometric']['real_time_exception_victim'],project_cc['prohibited_practice']['biometric']['real_time_exception_threat'], project_cc['prohibited_practice']['biometric']['real_time_exception_investigation']])) == 0:
|
306 |
-
print("You are engaged in a prohibited practice and thus the project is non-compliant.")
|
307 |
-
return True
|
308 |
-
else:
|
309 |
-
print("You are not engaged in any prohibited practices.")
|
310 |
-
return False
|
311 |
-
|
312 |
-
def check_all_true(file_path):
|
313 |
-
# Load the YAML file
|
314 |
-
with open("./project_cc.yaml", 'r') as file:
|
315 |
-
data = yaml.safe_load(file)
|
316 |
-
|
317 |
-
# Iterate through top-level keys
|
318 |
-
for top_key, top_value in data.items():
|
319 |
-
if isinstance(top_value, dict):
|
320 |
-
# Iterate through second-level keys
|
321 |
-
for second_key, second_value in top_value.items():
|
322 |
-
if not second_value:
|
323 |
-
print("You are non-compliant with the Act")
|
324 |
-
break
|
325 |
-
else:
|
326 |
-
print("No problems here")
|
327 |
-
|
328 |
-
def main():
|
329 |
-
# Prompt the user to enter a filename
|
330 |
-
file_path = "./" # input("Please enter a file path to the folder containing all your AI project's Compliance Cards: ")
|
331 |
-
|
332 |
-
# Call the function with the entered filename
|
333 |
-
check_for_project_cc(file_path)
|
334 |
-
|
335 |
-
if __name__ == "__main__":
|
336 |
-
main()
|
|
|
|
|
|
|
1 |
import yaml
|
2 |
+
from utils import set_type, set_operator_role_and_location, set_eu_market_status, check_within_scope
|
3 |
|
4 |
# Create some variables we will use throughout our analysis
|
5 |
|
|
|
25 |
}
|
26 |
}
|
27 |
|
28 |
+
def run_compliance_analysis_on_project(project_cc_yaml):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
# Determine project type (AI system vs. GPAI model) as well as operator type. We will use these for different things.
|
31 |
+
project_type = set_type(project_variables, project_cc_yaml)
|
32 |
set_operator_role_and_location(project_variables, project_cc_yaml)
|
33 |
set_eu_market_status(project_variables, project_cc_yaml)
|
34 |
|
35 |
# Check if the project is within scope of the Act. If it's not, the analysis is over.
|
36 |
if check_within_scope(project_cc_yaml):
|
37 |
+
msg = ("Project is within the scope of Act. Let's continue...")
|
38 |
else:
|
39 |
+
msg = ("Project is not within the scope of what is regulated by the Act.")
|
40 |
|
41 |
+
# # Check for prohibited practices. If any exist, the analysis is over.
|
42 |
+
# if check_prohibited(project_cc_yaml) == True:
|
43 |
+
# print("Project contains prohibited practices and is therefore non-compliant.")
|
44 |
+
# msg = ("Project is non-compliant due to a prohibited practice.")
|
45 |
+
# else:
|
46 |
+
# print("Project does not contain prohibited practies. Let's continue...")
|
47 |
|
48 |
# If project is high-risk AI system, check that is has met all the requirements for such systems:
|
49 |
|
50 |
+
if project_type == "high_risk_ai_system":
|
51 |
|
52 |
# Do this by examining the Project CC
|
53 |
|
54 |
for key, value in project_cc_yaml['risk_management_system']:
|
55 |
if not value:
|
56 |
+
msg = ("Because of project-level characteristics, this high-risk AI system fails the risk management requirements under Article 9.")
|
57 |
for key, value in project_cc_yaml['technical_documentation']:
|
58 |
if not value:
|
59 |
+
msg = ("Because of project-level characteristics, this high-risk AI system fails the risk management requirements under Article 11.")
|
60 |
for key, value in project_cc_yaml['record_keeping']:
|
61 |
if not value:
|
62 |
+
msg = ("Because of project-level characteristics, this high-risk AI system fails the risk management requirements under Article 12.")
|
63 |
for key, value in project_cc_yaml['transparency_and_provision_of_information_to_deployers']:
|
64 |
if not value:
|
65 |
+
msg = ("Because of project-level characteristics, this high-risk AI system fails the transparency requirements under Article 13.")
|
66 |
for key, value in project_cc_yaml['human_oversight']:
|
67 |
if not value:
|
68 |
+
msg = ("Because of project-level characteristics, this high-risk AI system fails the human oversight requirements under Article 14.")
|
69 |
for key, value in project_cc_yaml['accuracy_robustness_cybersecurity']:
|
70 |
if not value:
|
71 |
+
msg = ("Because of project-level characteristics, this high-risk AI system fails the accuracy, robustness, and cybersecurity requirements under Article 15.")
|
72 |
for key, value in project_cc_yaml['quality_management_system']:
|
73 |
if not value:
|
74 |
+
msg = ("Because of project-level characteristics, this high-risk AI system fails the accuracy, robustness, and cybersecurity requirements under Article 17.")
|
75 |
+
|
76 |
+
return msg
|
77 |
|
78 |
+
def run_compliance_analysis_on_data(data_cc_yaml):
|
79 |
# Do this by examining any and all Data CCs too
|
80 |
+
data_cc_yaml = yaml.safe_load(data_cc_yaml)
|
81 |
+
filename = data_cc_yaml
|
82 |
+
|
83 |
+
for key, value in data_cc_yaml['data_and_data_governance']:
|
84 |
+
if not value:
|
85 |
+
msg = (f"Because of the dataset represented by {filename}, this high-risk AI system fails the data and data governance requirements under Article 10.")
|
86 |
+
for key, value in data_cc_yaml['technical_documentation']:
|
87 |
+
if not value:
|
88 |
+
msg = (f"Because of the dataset represented by {filename}, this high-risk AI system fails the technical documentation requirements under Article 11.")
|
89 |
+
for key, value in data_cc_yaml['transparency_and_provision_of_information_to_deployers']:
|
90 |
+
if not value:
|
91 |
+
msg = (f"Because of the dataset represented by {filename}, this high-risk AI system fails the transparency requirements under Article 13.")
|
92 |
+
for key, value in data_cc_yaml['quality_management_system']:
|
93 |
+
if not value:
|
94 |
+
msg = (f"Because of the dataset represented by {filename}, this high-risk AI system fails the quality management requirements under Article 17.")
|
95 |
+
|
96 |
+
return msg
|
97 |
+
|
98 |
+
def run_compliance_analysis_on_data(model_cc_yaml):
|
99 |
+
|
100 |
+
model_cc_yaml = yaml.safe_load(model_cc_yaml)
|
101 |
+
filename - model_cc_yaml
|
102 |
+
|
103 |
+
for key, value in model_cc_yaml['risk_management_system']:
|
104 |
+
if not value:
|
105 |
+
msg = (f"Because of the model represented by {filename}, this high-risk AI system fails the risk management requirements under Article 9.")
|
106 |
+
for key, value in data_cc_yaml['technical_documentation']:
|
107 |
+
if not value:
|
108 |
+
msg = (f"Because of the model represented by {filename}, this high-risk AI system fails the technical documentation requirements under Article 11.")
|
109 |
+
for key, value in data_cc_yaml['transparency_and_provision_of_information_to_deployers']:
|
110 |
+
if not value:
|
111 |
+
msg = (f"Because of the model represented by {filename}, this high-risk AI system fails the transparency requirements under Article 13.")
|
112 |
+
for key, value in data_cc_yaml['accuracy_robustness_cybersecurity']:
|
113 |
+
if not value:
|
114 |
+
msg = (f"Because of the model represented by {filename}, this high-risk AI system fails the quality management requirements under Article 15.")
|
115 |
+
for key, value in data_cc_yaml['quality_management_system']:
|
116 |
+
if not value:
|
117 |
+
msg = (f"Because of the model represented by {filename}, this high-risk AI system fails the quality management requirements under Article 17.")
|
118 |
+
|
119 |
+
return msg
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
+
# # If the project is a GPAI model, check that is has met all the requirements for such systems:
|
123 |
|
124 |
+
# if gpai_model:
|
|
|
|
|
125 |
|
126 |
+
# # Do this by examining the Project CC
|
127 |
+
|
128 |
+
# for key, value in project_cc_yaml['gpai_model_provider_obligations']:
|
129 |
+
# if not value:
|
130 |
+
# msg = ("GPAI model fails the transparency requirements under Article 53.")
|
131 |
|
132 |
+
# # Do this by examining any and all Data CCs too
|
|
|
|
|
133 |
|
134 |
+
# for filename in os.listdir(folder_path):
|
135 |
+
# # Check if the search word is in the filename
|
136 |
+
# if "data_cc.md" in filename.lower():
|
137 |
|
138 |
+
# # If it is, load the yaml
|
|
|
139 |
|
140 |
+
# with open(folder_path + filename, 'r') as file:
|
141 |
+
# data_cc_yaml = yaml.safe_load(file)
|
|
|
142 |
|
143 |
+
# for key, value in data_cc_yaml['gpai_requirements']['gpai_requirements']:
|
144 |
+
# if not value:
|
145 |
+
# msg = (f"Because of the dataset represented by {filename}, this GPAI fails the transparency requirements under Article 53.")
|
146 |
+
|
147 |
+
# # Do this by examining any and all Model CCs too
|
148 |
|
149 |
+
# for filename in os.listdir(folder_path):
|
150 |
+
# # Check if the search word is in the filename
|
151 |
+
# if "model_cc.md" in filename.lower():
|
152 |
|
153 |
+
# # If it is, load the yaml
|
154 |
|
155 |
+
# with open(folder_path + filename, 'r') as file:
|
156 |
+
# model_cc_yaml = yaml.safe_load(file)
|
157 |
|
158 |
+
# for key, value in model_cc_yaml['obligations_for_providers_of_gpai_models']:
|
159 |
+
# if not value:
|
160 |
+
# msg = (f"Because of the model represented by {filename}, this GPAI fails the transparency requirements under Article 53.")
|
161 |
|
162 |
+
# # If the project is a GPAI model with systematic risk, check that is has additionally met all the requirements for such systems:
|
163 |
|
164 |
+
# if gpai_model_systematic_risk:
|
165 |
+
|
166 |
+
# # Do this by examining the Project CC
|
167 |
+
|
168 |
+
# for key, value in project_cc_yaml['gpai_obligations_for_systemic_risk_models']:
|
169 |
+
# if not value:
|
170 |
+
# msg = ("GPAI model with systematic risk fails the transparency requirements under Article 55.")
|
171 |
+
|
172 |
+
# # Do this by examining any and all Model CCs too
|
173 |
+
|
174 |
+
# for filename in os.listdir(folder_path):
|
175 |
+
# # Check if the search word is in the filename
|
176 |
+
# if "model_cc.md" in filename.lower():
|
177 |
+
|
178 |
+
# # If it is, load the yaml
|
179 |
+
|
180 |
+
# with open(folder_path + filename, 'r') as file:
|
181 |
+
# model_cc_yaml = yaml.safe_load(file)
|
182 |
+
|
183 |
+
# for key, value in model_cc_yaml['obligations_for_providers_of_gpai_models_with_systemic_risk']:
|
184 |
+
# if not value:
|
185 |
+
# msg = (f"Because of the model represented by {filename}, this GPAI model with systematic risk fails the transparency requirements under Article 55.")
|
186 |
|
|
|
187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import yaml
|
2 |
+
|
3 |
+
def set_type(project_variables, project_cc_yaml):
|
4 |
+
|
5 |
+
project_type = None
|
6 |
+
|
7 |
+
ai_system = project_variables['ai_project_type']['ai_system']
|
8 |
+
gpai_model = project_variables['ai_project_type']['gpai_model']
|
9 |
+
|
10 |
+
if project_cc_yaml['ai_system']['ai_system']['value']:
|
11 |
+
ai_system = True
|
12 |
+
if project_cc_yaml['gpai_model']['gpai_model']['value']:
|
13 |
+
gpai_model = True
|
14 |
+
if ai_system and gpai_model:
|
15 |
+
msg = ("Your project cannot be both an AI system and a GPAI model. Please revise your Project CC accordingly.")
|
16 |
+
if ai_system == True:
|
17 |
+
for key, value in project_cc_yaml['high_risk_ai_system']:
|
18 |
+
if value and sum(map(bool, [project_cc_yaml['high_risk_ai_system']['filter_exception_rights'],project_cc_yaml['high_risk_ai_system']['filter_exception_narrow'],project_cc_yaml['high_risk_ai_system']['filter_exception_human'],project_cc_yaml['high_risk_ai_system']['filter_exception_deviation'], project_cc_yaml['high_risk_ai_system']['filter_exception_prep']])) < 1:
|
19 |
+
project_type = "high_risk_ai_system"
|
20 |
+
|
21 |
+
if gpai_model == True:
|
22 |
+
if project_cc_yaml['gpai_model_systematic_risk']['evaluation'] or project_cc_yaml['gpai_model_systematic_risk']['flops']:
|
23 |
+
project_type = "gpai_model_systematic_risk"
|
24 |
+
|
25 |
+
return project_type
|
26 |
+
|
27 |
+
def set_operator_role_and_location(project_variables, project_cc_yaml):
|
28 |
+
operators = 0
|
29 |
+
|
30 |
+
ai_system = project_variables['ai_project_type']['ai_system']
|
31 |
+
gpai_model = project_variables['ai_project_type']['gpai_model']
|
32 |
+
|
33 |
+
for var in project_variables['operator_role']:
|
34 |
+
if project_cc_yaml['operator_role'][f'{var}']['value']:
|
35 |
+
project_variables['operator_role'][f'{var}'] = True
|
36 |
+
operators += 1
|
37 |
+
|
38 |
+
if ai_system and gpai_model:
|
39 |
+
msg = ("Your project cannot be both an AI system and a GPAI model. Please revise your Project CC accordingly.")
|
40 |
+
if operators != 1:
|
41 |
+
msg = ("Please specify exactly one operator role.")
|
42 |
+
|
43 |
+
return project_variables
|
44 |
+
|
45 |
+
def set_eu_market_status(project_variables, project_cc_yaml):
|
46 |
+
|
47 |
+
if project_cc_yaml['eu_market_status']['placed_on_market']['value']:
|
48 |
+
project_variables['eu_market_status']["placed_on_market"] = True
|
49 |
+
if project_cc_yaml['eu_market_status']['put_into_service']['value']:
|
50 |
+
project_variables['eu_market_status']["put_into_service"] = True
|
51 |
+
|
52 |
+
if project_cc_yaml['operator_role']['output_used']['value']:
|
53 |
+
project_variables['operator_role']["output_used"] = True
|
54 |
+
|
55 |
+
return project_variables
|
56 |
+
|
57 |
+
|
58 |
+
def check_within_scope(project_cc_yaml):
|
59 |
+
if not check_excepted(project_cc_yaml):
|
60 |
+
if provider and ((ai_system and (placed_on_market or put_into_service)) or (gpai_model and placed_on_market)): # Article 2.1(a)
|
61 |
+
return True
|
62 |
+
if deployer and eu_located: # Article 2.1(b)
|
63 |
+
return True
|
64 |
+
if (provider or deployer) and (ai_system and eu_located and output_used): # Article 2.1(c)
|
65 |
+
return True
|
66 |
+
if (importer or distributor) and ai_system: # Article 2.1(d)
|
67 |
+
return True
|
68 |
+
if product_manufacturer and ai_system and (placed_on_market or put_into_service): # Article 2.1(e)
|
69 |
+
return True
|
70 |
+
else:
|
71 |
+
return False
|
72 |
+
|
73 |
+
def check_excepted(project_cc_yaml):
|
74 |
+
if project_cc_yaml['excepted']['scientific'] or project_cc_yaml['excepted']['pre_market'] or (ai_system and project_cc_yaml['excepted']['open_source_ai_system']) or (gpai_model and project_cc_yaml['excepted']['open_source_gpai_system']):
|
75 |
+
return True
|
76 |
+
else:
|
77 |
+
return False
|
78 |
+
|
79 |
+
# def check_prohibited (project_cc_yaml):
|
80 |
+
# if ai_system:
|
81 |
+
# for key in project_cc_yaml['prohibited_practice']['ai_system']:
|
82 |
+
# if key[value]:
|
83 |
+
# print("You are engaged in a prohibited practice and thus the project is non-compliant.")
|
84 |
+
# return True
|
85 |
+
# if project_cc_yaml['prohibited_practice']['biometric']['categorization']:
|
86 |
+
# print("You are engaged in a prohibited practice and thus the project is non-compliant.")
|
87 |
+
# return True
|
88 |
+
# if project_cc_yaml['prohibited_practice']['biometric']['real_time'] and sum(map(bool, [project_cc_yaml['prohibited_practice']['biometric']['real_time_exception_victim'],project_cc['prohibited_practice']['biometric']['real_time_exception_threat'], project_cc_yaml['prohibited_practice']['biometric']['real_time_exception_investigation']])) == 0:
|
89 |
+
# print("You are engaged in a prohibited practice and thus the project is non-compliant.")
|
90 |
+
# return True
|
91 |
+
# else:
|
92 |
+
# print("You are not engaged in any prohibited practices.")
|
93 |
+
# return False
|
94 |
+
|
95 |
+
# def check_all_true(file_path):
|
96 |
+
# data = yaml.safe_load(file_path)
|
97 |
+
|
98 |
+
# # Iterate through top-level keys
|
99 |
+
# for top_key, top_value in data.items():
|
100 |
+
# if isinstance(top_value, dict):
|
101 |
+
# # Iterate through second-level keys
|
102 |
+
# for second_key, second_value in top_value.items():
|
103 |
+
# if not second_value:
|
104 |
+
# print("You are non-compliant with the Act")
|
105 |
+
# break
|
106 |
+
# else:
|
107 |
+
# print("No problems here")
|