qqubb commited on
Commit
b5c1e12
·
1 Parent(s): 8d296cc

add data structure for messages specifying non-compliant cards , add check for missing cards

Browse files
__pycache__/compliance_analysis.cpython-310.pyc CHANGED
Binary files a/__pycache__/compliance_analysis.cpython-310.pyc and b/__pycache__/compliance_analysis.cpython-310.pyc differ
 
app.py CHANGED
@@ -125,6 +125,12 @@ with project_col:
125
  with data_col:
126
 
127
  st.title("Data Card")
 
 
 
 
 
 
128
  if cards['data_files']:
129
  for card in cards['data_files']:
130
  data_cc = card[1]
@@ -212,4 +218,4 @@ with model_col:
212
 
213
  if st.button(f"Run Analysis"):
214
  results = compliance_analysis(cards)
215
- st.write("Analysis Results", results)
 
125
  with data_col:
126
 
127
  st.title("Data Card")
128
+ # if st.button(f"Add Data Card"):
129
+ # cc = load_yaml('./examples/cc_templates/data_cc.yaml')
130
+ # print(cc)
131
+ # card_type = cc['card_details'].get('card_type', '').lower()
132
+ # cards["data_files"].append((cc['card_details']['card_label'], cc))
133
+
134
  if cards['data_files']:
135
  for card in cards['data_files']:
136
  data_cc = card[1]
 
218
 
219
  if st.button(f"Run Analysis"):
220
  results = compliance_analysis(cards)
221
+ st.write("Analysis Results:", results)
compliance_analysis.py CHANGED
@@ -2,6 +2,11 @@ import yaml
2
  from utils import set_operator_role_and_location, set_eu_market_status, check_within_scope_act, check_prohibited
3
 
4
  def check_overall_compliance_ui(cards):
 
 
 
 
 
5
 
6
  project_cc = cards['project_file']
7
 
@@ -23,8 +28,10 @@ def check_overall_compliance_ui(cards):
23
  },
24
  "project_intended_purposes": [],
25
  "project_cc_pass": False,
26
- "data_cc_pass": False,
27
- "model_cc_pass": False,
 
 
28
  "msg": []
29
  }
30
 
@@ -262,6 +269,7 @@ def check_intended_purpose(dispositive_variables, project_cc, other_cc):
262
 
263
  if other_cc['card_details']['card_type'] == 'data':
264
  data_cc = other_cc
 
265
  for key in data_cc['intended_purpose']:
266
  if data_cc['intended_purpose'][f'{key}']['value']:
267
  dataset_intended_purposes.append(key)
@@ -269,11 +277,19 @@ def check_intended_purpose(dispositive_variables, project_cc, other_cc):
269
  for purpose in project_intended_purposes:
270
  if purpose not in dataset_intended_purposes:
271
  dispositive_variables['msg'].append(f"You are not compliant because {purpose} is not a valid purpose for {data_cc['card_details']['card_label']}")
272
-
 
 
 
 
 
 
 
273
  # model intended purposes
274
 
275
  if other_cc['card_details']['card_type'] == 'model':
276
- model_cc = other_cc
 
277
  for key in model_cc['intended_purpose']:
278
  if model_cc['intended_purpose'][f'{key}']['value']:
279
  model_intended_purposes.append(key)
@@ -281,6 +297,14 @@ def check_intended_purpose(dispositive_variables, project_cc, other_cc):
281
  for purpose in project_intended_purposes:
282
  if purpose not in model_intended_purposes:
283
  dispositive_variables['msg'].append(f"You are not compliant because {purpose} is not a valid purpose for {model_cc['card_details']['card_label']}")
 
 
 
 
 
 
 
 
284
 
285
  dispositive_variables['project_intended_purposes'] = project_intended_purposes
286
 
 
2
  from utils import set_operator_role_and_location, set_eu_market_status, check_within_scope_act, check_prohibited
3
 
4
  def check_overall_compliance_ui(cards):
5
+ # {"project_file": None, "data_files": [], "model_files": []}
6
+ if cards["project_file"] == None:
7
+ return "no project compliance card loaded"
8
+ if len(cards["data_files"]) == 0 or len(cards["model_files"]) == 0:
9
+ return "missing data or model compliance card"
10
 
11
  project_cc = cards['project_file']
12
 
 
28
  },
29
  "project_intended_purposes": [],
30
  "project_cc_pass": False,
31
+ "data_cc_compliant": [],
32
+ "model_cc_compliant": [],
33
+ "data_cc_non-compliant": {},
34
+ "model_cc_non-compliant": {},
35
  "msg": []
36
  }
37
 
 
269
 
270
  if other_cc['card_details']['card_type'] == 'data':
271
  data_cc = other_cc
272
+ card_label = data_cc['card_details']['card_label']
273
  for key in data_cc['intended_purpose']:
274
  if data_cc['intended_purpose'][f'{key}']['value']:
275
  dataset_intended_purposes.append(key)
 
277
  for purpose in project_intended_purposes:
278
  if purpose not in dataset_intended_purposes:
279
  dispositive_variables['msg'].append(f"You are not compliant because {purpose} is not a valid purpose for {data_cc['card_details']['card_label']}")
280
+ if not card_label in dispositive_variables['data_cc_non-compliant']:
281
+ dispositive_variables['data_cc_non-compliant'][card_label] = {
282
+ "intended_purpose": []
283
+ }
284
+ dispositive_variables['data_cc_non-compliant'][card_label]['intended_purpose'].append((f"{purpose}"))
285
+ else:
286
+ dispositive_variables['data_cc_compliant'].append(data_cc['card_details']['card_label'])
287
+
288
  # model intended purposes
289
 
290
  if other_cc['card_details']['card_type'] == 'model':
291
+ model_cc = other_cc
292
+ card_label = model_cc['card_details']['card_label']
293
  for key in model_cc['intended_purpose']:
294
  if model_cc['intended_purpose'][f'{key}']['value']:
295
  model_intended_purposes.append(key)
 
297
  for purpose in project_intended_purposes:
298
  if purpose not in model_intended_purposes:
299
  dispositive_variables['msg'].append(f"You are not compliant because {purpose} is not a valid purpose for {model_cc['card_details']['card_label']}")
300
+ if not card_label in dispositive_variables['data_cc_non-compliant']:
301
+ dispositive_variables['model_cc_non-compliant'][card_label] = {
302
+ "intended_purpose": []
303
+ }
304
+ dispositive_variables['model_cc_non-compliant'][card_label]['intended_purpose'].append((f"{purpose}"))
305
+ dispositive_variables['model_cc_non-compliant'].append(f"{model_cc['card_details']['card_label']}, intended_purpose: {purpose}")
306
+ else:
307
+ dispositive_variables['model_cc_compliant'].append(model_cc['card_details']['card_label'])
308
 
309
  dispositive_variables['project_intended_purposes'] = project_intended_purposes
310