qqubb commited on
Commit
cfd40e9
·
1 Parent(s): 4536d13

improve code in set_operator_role_and_location

Browse files
Files changed (2) hide show
  1. compliance_analysis.py +45 -40
  2. project_cc.yaml +1 -1
compliance_analysis.py CHANGED
@@ -5,24 +5,27 @@ from enum import Enum
5
 
6
  # Create some variables we will use throughout our analysis
7
 
8
- # Type of AI project (AI system vs GPAI model)
9
- ai_system = False
10
- gpai_model = False
11
- high_risk_ai_system = False
12
- gpai_model_systematic_risk = False
13
-
14
- # Role and location of AI project operator
15
- provider = False
16
- deployer = False
17
- importer = False
18
- distributor = False
19
- product_manufacturer = False
20
- eu_located = False
21
-
22
- #EU market status
23
- placed_on_market = False
24
- put_into_service = False
25
- output_used = False
 
 
 
26
 
27
  #Define a function that creates a list of all the files in a provided folder. We will use this list for different things.
28
  def create_list_of_files(folder_path):
@@ -61,8 +64,8 @@ def run_compliance_analysis(folder_path):
61
  project_cc_yaml = yaml.safe_load(file)
62
 
63
  # Determine project type (AI system vs. GPAI model) as well as operator type. We will use these for different things.
64
- set_type(project_cc_yaml)
65
- set_operator_role_and_location(project_cc_yaml)
66
  set_eu_market_status(project_cc_yaml)
67
 
68
  # Check if the project is within scope of the Act. If it's not, the analysis is over.
@@ -222,10 +225,12 @@ def run_compliance_analysis(folder_path):
222
  if not value:
223
  sys.exit(f"Because of the model represented by {filename}, this GPAI model with systematic risk fails the transparency requirements under Article 55.")
224
 
225
- def set_type(project_cc_yaml):
 
 
226
  if project_cc_yaml['ai_system']['ai_system']['value']:
227
  ai_system = True
228
- if project_cc_yaml['gpai_model']['ai_system']['value']:
229
  gpai_model = True
230
  if ai_system and gpai_model:
231
  sys.exit("Your project cannot be both an AI system and a GPAI model. Please revise your Project CC accordingly.")
@@ -237,25 +242,25 @@ def set_type(project_cc_yaml):
237
  if project_cc_yaml['gpai_model_systematic_risk']['evaluation'] or project_cc_yaml['gpai_model_systematic_risk']['flops']:
238
  gpai_model_systematic_risk == True
239
 
240
- def set_operator_role_and_location(project_cc):
241
- if project_cc_yaml['operator_role']['eu_located']['value']:
242
- eu_located = True
243
- if project_cc_yaml['operator_role']['provider']['value']:
244
- provider = True
245
- if project_cc_yaml['operator_role']['deployer']['value']:
246
- deployer = True
247
- if project_cc_yaml['operator_role']['importer']['value']:
248
- importer = True
249
- if project_cc_yaml['operator_role']['distributor']['value']:
250
- distributor = True
251
- if project_cc_yaml['operator_role']['product_manufacturer']['value']:
252
- product_manufacturer = True
253
  if ai_system and gpai_model:
254
  sys.exit("Your project cannot be both an AI system and a GPAI model. Please revise your Project CC accordingly.")
255
- if sum(map(bool, [provider,deployer,importer,distributor, product_manufacturer])) != 1:
256
  sys.exit("Please specify exactly one operator role.")
 
 
257
 
258
- def set_eu_market_status(project_cc):
259
  if project_cc_yaml['eu_market']['placed_on_market']['value']:
260
  placed_on_market = True
261
  if project_cc_yaml['eu_market']['put_into_service']['value']:
@@ -278,13 +283,13 @@ def check_within_scope(project_cc):
278
  else:
279
  return False
280
 
281
- def check_excepted(project_cc):
282
  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']):
283
  return True
284
  else:
285
  return False
286
 
287
- def check_prohibited (project_cc):
288
  if ai_system:
289
  for key in project_cc_yaml['prohibited_practice']['ai_system']:
290
  if key[value]:
@@ -322,7 +327,7 @@ def check_all_true(file_path):
322
 
323
  def main():
324
  # Prompt the user to enter a filename
325
- file_path = input("Please enter a file path to the folder containing all your AI project's Compliance Cards: ")
326
 
327
  # Call the function with the entered filename
328
  check_for_project_cc(file_path)
 
5
 
6
  # Create some variables we will use throughout our analysis
7
 
8
+ project_variables = {
9
+ "ai_project_type": {
10
+ "ai_system": False,
11
+ "gpai_model": False,
12
+ "high_risk_ai_system": False,
13
+ "gpai_model_systematic_risk": False
14
+ },
15
+ "operator_role": {
16
+ "provider": False,
17
+ "deployer": False,
18
+ "importer": False,
19
+ "distributor": False,
20
+ "product_manufacturer": False,
21
+ "eu_located": False
22
+ },
23
+ "eu_market_status": {
24
+ "placed_on_market": False,
25
+ "put_into_service": False,
26
+ "output_used": False
27
+ }
28
+ }
29
 
30
  #Define a function that creates a list of all the files in a provided folder. We will use this list for different things.
31
  def create_list_of_files(folder_path):
 
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_cc_yaml)
70
 
71
  # Check if the project is within scope of the Act. If it's not, the analysis is over.
 
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.")
 
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_cc_yaml):
264
  if project_cc_yaml['eu_market']['placed_on_market']['value']:
265
  placed_on_market = True
266
  if project_cc_yaml['eu_market']['put_into_service']['value']:
 
283
  else:
284
  return False
285
 
286
+ def check_excepted(project_cc_yaml):
287
  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']):
288
  return True
289
  else:
290
  return False
291
 
292
+ def check_prohibited (project_cc_yaml):
293
  if ai_system:
294
  for key in project_cc_yaml['prohibited_practice']['ai_system']:
295
  if key[value]:
 
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)
project_cc.yaml CHANGED
@@ -22,7 +22,7 @@ operator_role:
22
  value: !!bool false
23
  eu_located: # Art. 2
24
  verbose: 'AI project operator has its place of establishment or location within the Union'
25
- value: !!bool false
26
  output_used: # Art. 2
27
  verbose: 'The output produced by the AI system is used in the Union'
28
  value: !!bool false
 
22
  value: !!bool false
23
  eu_located: # Art. 2
24
  verbose: 'AI project operator has its place of establishment or location within the Union'
25
+ value: !!bool True
26
  output_used: # Art. 2
27
  verbose: 'The output produced by the AI system is used in the Union'
28
  value: !!bool false