Spaces:
Running
Running
iv_update_risk_atlas_nexus_version (#3)
Browse files- Update to also show ai eval benchmarks and risk controls, where available (e9b41a7d8e7ad3438660890db492287a07e1cb63)
Co-authored-by: Inge V <ingelise@users.noreply.huggingface.co>
- app.py +13 -4
- executor.py +33 -6
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -65,7 +65,7 @@ class UI:
|
|
| 65 |
with gr.Column(scale=2):
|
| 66 |
|
| 67 |
self.assessment_sec = gr.Markdown()
|
| 68 |
-
self.assessed_risks = gr.Dataset(label=None, visible=False)
|
| 69 |
self.assessed_risk_definition = gr.Markdown()
|
| 70 |
|
| 71 |
gr.Markdown(
|
|
@@ -74,7 +74,7 @@ class UI:
|
|
| 74 |
"""
|
| 75 |
)
|
| 76 |
rrtb = gr.Markdown()
|
| 77 |
-
self.relatedrisks = gr.Dataset(components=[rrtb], label=None, visible=False)
|
| 78 |
|
| 79 |
gr.Markdown(
|
| 80 |
"""<h2> Mitigations </h2>
|
|
@@ -82,8 +82,16 @@ class UI:
|
|
| 82 |
)
|
| 83 |
self.mitigations_text = gr.Markdown()
|
| 84 |
self.mitigations = gr.DataFrame(label=None, visible=False)
|
| 85 |
-
self.download = gr.DownloadButton("Download JSON", visible=False)
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
gr.Markdown("---")
|
| 88 |
gr.Markdown("<br>")
|
| 89 |
|
|
@@ -119,8 +127,9 @@ class UI:
|
|
| 119 |
fn=mitigations,
|
| 120 |
inputs=[self.assessed_risks, self.taxonomy],
|
| 121 |
# NOTETOSELF: Intent based risk is stored in self.risk (if needed)
|
| 122 |
-
outputs=[self.assessed_risk_definition, self.relatedrisks, self.mitigations, self.mitigations_text]
|
| 123 |
)
|
|
|
|
| 124 |
return demo
|
| 125 |
|
| 126 |
|
|
|
|
| 65 |
with gr.Column(scale=2):
|
| 66 |
|
| 67 |
self.assessment_sec = gr.Markdown()
|
| 68 |
+
self.assessed_risks = gr.Dataset(elem_classes="risks", label=None, visible=False)
|
| 69 |
self.assessed_risk_definition = gr.Markdown()
|
| 70 |
|
| 71 |
gr.Markdown(
|
|
|
|
| 74 |
"""
|
| 75 |
)
|
| 76 |
rrtb = gr.Markdown()
|
| 77 |
+
self.relatedrisks = gr.Dataset(elem_classes="related-risks", components=[rrtb], label=None, visible=False)
|
| 78 |
|
| 79 |
gr.Markdown(
|
| 80 |
"""<h2> Mitigations </h2>
|
|
|
|
| 82 |
)
|
| 83 |
self.mitigations_text = gr.Markdown()
|
| 84 |
self.mitigations = gr.DataFrame(label=None, visible=False)
|
|
|
|
| 85 |
|
| 86 |
+
gr.Markdown(
|
| 87 |
+
"""<h2>Benchmarks </h2>
|
| 88 |
+
Select a potential risk to determine possible AI evaluations. """
|
| 89 |
+
)
|
| 90 |
+
self.benchmarks_text = gr.Markdown()
|
| 91 |
+
self.benchmarks = gr.DataFrame(label=None, visible=False)
|
| 92 |
+
|
| 93 |
+
self.download = gr.DownloadButton("Download JSON", visible=False)
|
| 94 |
+
|
| 95 |
gr.Markdown("---")
|
| 96 |
gr.Markdown("<br>")
|
| 97 |
|
|
|
|
| 127 |
fn=mitigations,
|
| 128 |
inputs=[self.assessed_risks, self.taxonomy],
|
| 129 |
# NOTETOSELF: Intent based risk is stored in self.risk (if needed)
|
| 130 |
+
outputs=[self.assessed_risk_definition, self.relatedrisks, self.mitigations, self.benchmarks, self.mitigations_text]
|
| 131 |
)
|
| 132 |
+
|
| 133 |
return demo
|
| 134 |
|
| 135 |
|
executor.py
CHANGED
|
@@ -45,7 +45,9 @@ def risk_identifier(usecase: str,
|
|
| 45 |
usecases=[usecase],
|
| 46 |
inference_engine=inference_engine,
|
| 47 |
taxonomy=taxonomy,
|
|
|
|
| 48 |
)[0]
|
|
|
|
| 49 |
|
| 50 |
sample_labels = [r.name if r else r.id for r in risks]
|
| 51 |
|
|
@@ -68,12 +70,13 @@ def risk_identifier(usecase: str,
|
|
| 68 |
|
| 69 |
|
| 70 |
@lru_cache
|
| 71 |
-
def mitigations(riskid: str, taxonomy: str) -> tuple[gr.Markdown, gr.Dataset, gr.DataFrame, gr.Markdown]:
|
| 72 |
"""
|
| 73 |
For a specific risk (riskid), returns
|
| 74 |
(a) a risk description
|
| 75 |
(b) related risks - as a dataset
|
| 76 |
(c) mitigations
|
|
|
|
| 77 |
|
| 78 |
"""
|
| 79 |
|
|
@@ -84,8 +87,10 @@ def mitigations(riskid: str, taxonomy: str) -> tuple[gr.Markdown, gr.Dataset, gr
|
|
| 84 |
risk_sec = ""
|
| 85 |
|
| 86 |
related_risk_ids = [r.id for r in ran.get_related_risks(id=riskid)]
|
|
|
|
| 87 |
|
| 88 |
action_ids = []
|
|
|
|
| 89 |
|
| 90 |
if taxonomy == "ibm-risk-atlas":
|
| 91 |
# look for actions associated with related risks
|
|
@@ -94,12 +99,19 @@ def mitigations(riskid: str, taxonomy: str) -> tuple[gr.Markdown, gr.Dataset, gr
|
|
| 94 |
rai = ran.get_related_actions(id=i)
|
| 95 |
if rai:
|
| 96 |
action_ids += rai
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
else:
|
| 99 |
action_ids = []
|
|
|
|
| 100 |
else:
|
| 101 |
# Use only actions related to primary risks
|
| 102 |
action_ids = ran.get_related_actions(id=riskid)
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# Sanitize outputs
|
| 105 |
if not related_risk_ids:
|
|
@@ -111,22 +123,37 @@ def mitigations(riskid: str, taxonomy: str) -> tuple[gr.Markdown, gr.Dataset, gr
|
|
| 111 |
samples = related_risk_ids
|
| 112 |
sample_labels = [i.name for i in ran.get_related_risks(id=riskid)] #type: ignore
|
| 113 |
|
| 114 |
-
if not action_ids:
|
| 115 |
alabel = "No mitigations found."
|
| 116 |
asamples = None
|
| 117 |
asample_labels = None
|
| 118 |
mitdf = pd.DataFrame()
|
| 119 |
|
| 120 |
else:
|
| 121 |
-
alabel = f"Mitigation actions related to risk {riskid}."
|
| 122 |
asamples = action_ids
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 125 |
mitdf = pd.DataFrame({"Mitigation": asample_name, "Description": asample_labels})
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
status = gr.Markdown(" ") if len(mitdf) > 0 else gr.Markdown("No mitigations found.")
|
| 128 |
|
| 129 |
return (gr.Markdown(risk_sec),
|
| 130 |
gr.Dataset(samples=samples, label=label, sample_labels=sample_labels, visible=True),
|
| 131 |
gr.DataFrame(mitdf, wrap=True, show_copy_button=True, show_search="search", label=alabel, visible=True),
|
|
|
|
| 132 |
status)
|
|
|
|
|
|
| 45 |
usecases=[usecase],
|
| 46 |
inference_engine=inference_engine,
|
| 47 |
taxonomy=taxonomy,
|
| 48 |
+
max_risk=5
|
| 49 |
)[0]
|
| 50 |
+
|
| 51 |
|
| 52 |
sample_labels = [r.name if r else r.id for r in risks]
|
| 53 |
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
@lru_cache
|
| 73 |
+
def mitigations(riskid: str, taxonomy: str) -> tuple[gr.Markdown, gr.Dataset, gr.DataFrame, gr.DataFrame, gr.Markdown]:
|
| 74 |
"""
|
| 75 |
For a specific risk (riskid), returns
|
| 76 |
(a) a risk description
|
| 77 |
(b) related risks - as a dataset
|
| 78 |
(c) mitigations
|
| 79 |
+
(d) related ai evaluations
|
| 80 |
|
| 81 |
"""
|
| 82 |
|
|
|
|
| 87 |
risk_sec = ""
|
| 88 |
|
| 89 |
related_risk_ids = [r.id for r in ran.get_related_risks(id=riskid)]
|
| 90 |
+
related_ai_eval_ids = [ai_eval.id for ai_eval in ran.get_related_evaluations(risk_id=riskid)]
|
| 91 |
|
| 92 |
action_ids = []
|
| 93 |
+
control_ids =[]
|
| 94 |
|
| 95 |
if taxonomy == "ibm-risk-atlas":
|
| 96 |
# look for actions associated with related risks
|
|
|
|
| 99 |
rai = ran.get_related_actions(id=i)
|
| 100 |
if rai:
|
| 101 |
action_ids += rai
|
| 102 |
+
|
| 103 |
+
rac = ran.get_related_risk_controls(id=i)
|
| 104 |
+
if rac:
|
| 105 |
+
control_ids += rac
|
| 106 |
|
| 107 |
else:
|
| 108 |
action_ids = []
|
| 109 |
+
control_ids = []
|
| 110 |
else:
|
| 111 |
# Use only actions related to primary risks
|
| 112 |
action_ids = ran.get_related_actions(id=riskid)
|
| 113 |
+
control_ids = ran.get_related_risk_controls(id=riskid)
|
| 114 |
+
|
| 115 |
|
| 116 |
# Sanitize outputs
|
| 117 |
if not related_risk_ids:
|
|
|
|
| 123 |
samples = related_risk_ids
|
| 124 |
sample_labels = [i.name for i in ran.get_related_risks(id=riskid)] #type: ignore
|
| 125 |
|
| 126 |
+
if not action_ids and not control_ids:
|
| 127 |
alabel = "No mitigations found."
|
| 128 |
asamples = None
|
| 129 |
asample_labels = None
|
| 130 |
mitdf = pd.DataFrame()
|
| 131 |
|
| 132 |
else:
|
| 133 |
+
alabel = f"Mitigation actions and controls related to risk {riskid}."
|
| 134 |
asamples = action_ids
|
| 135 |
+
asamples_ctl = control_ids
|
| 136 |
+
asample_labels = [ran.get_action_by_id(i).description for i in asamples] + [ran.get_risk_control(i.id).name for i in asamples_ctl]# type: ignore
|
| 137 |
+
asample_name = [ran.get_action_by_id(i).name for i in asamples] + [ran.get_risk_control(i.id).name for i in asamples_ctl] #type: ignore
|
| 138 |
mitdf = pd.DataFrame({"Mitigation": asample_name, "Description": asample_labels})
|
| 139 |
+
|
| 140 |
+
if not related_ai_eval_ids:
|
| 141 |
+
blabel = "No related AI evaluations found."
|
| 142 |
+
bsamples = None
|
| 143 |
+
bsample_labels = None
|
| 144 |
+
aievalsdf = pd.DataFrame()
|
| 145 |
+
else:
|
| 146 |
+
blabel = f"AI Evaluations related to {riskid}"
|
| 147 |
+
bsamples = related_ai_eval_ids
|
| 148 |
+
bsample_labels = [ran.get_evaluation(i).description for i in bsamples] # type: ignore
|
| 149 |
+
bsample_name = [ran.get_evaluation(i).name for i in bsamples] #type: ignore
|
| 150 |
+
aievalsdf = pd.DataFrame({"AI Evaluation": bsample_name, "Description": bsample_labels})
|
| 151 |
+
|
| 152 |
status = gr.Markdown(" ") if len(mitdf) > 0 else gr.Markdown("No mitigations found.")
|
| 153 |
|
| 154 |
return (gr.Markdown(risk_sec),
|
| 155 |
gr.Dataset(samples=samples, label=label, sample_labels=sample_labels, visible=True),
|
| 156 |
gr.DataFrame(mitdf, wrap=True, show_copy_button=True, show_search="search", label=alabel, visible=True),
|
| 157 |
+
gr.DataFrame(aievalsdf, wrap=True, show_copy_button=True, show_search="search", label=blabel, visible=True),
|
| 158 |
status)
|
| 159 |
+
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
gradio==5.18.0
|
| 2 |
-
pydantic==2.
|
| 3 |
linkml==1.8.6
|
| 4 |
linkml_runtime==1.8.3
|
| 5 |
ibm_watsonx_ai==1.2.8
|
|
|
|
| 1 |
gradio==5.18.0
|
| 2 |
+
pydantic==2.9.2
|
| 3 |
linkml==1.8.6
|
| 4 |
linkml_runtime==1.8.3
|
| 5 |
ibm_watsonx_ai==1.2.8
|