Skip to content

[Bug fix] Report generator script for PII operator #1149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions ads/dataset/recommendation.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8; -*-

# Copyright (c) 2020, 2022 Oracle and/or its affiliates.
# Copyright (c) 2020, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

import copy
import importlib

from ads.common.decorator.runtime_dependency import (
runtime_dependency,
OptionalDependency,
runtime_dependency,
)
from ads.dataset import logger

Expand Down Expand Up @@ -59,11 +58,10 @@ def on_action_change(change):
if change["type"] == "change" and change["name"] == "value":
if change["new"] == "Fill missing values with constant":
self._show_constant_fill_widget(column)
else:
if change["old"] == "Fill missing values with constant":
text = self.fill_nan_dict.pop(column, None)
if text is not None:
text.close()
elif change["old"] == "Fill missing values with constant":
text = self.fill_nan_dict.pop(column, None)
if text is not None:
text.close()
self.reco_dict[recommendation_type][column]["Selected Action"] = change[
"new"
]
Expand Down Expand Up @@ -151,7 +149,6 @@ def show_in_notebook(self):
@runtime_dependency(module="IPython", install_from=OptionalDependency.NOTEBOOK)
@runtime_dependency(module="ipywidgets", install_from=OptionalDependency.NOTEBOOK)
def _display(self):

from IPython.core.display import display

if self.recommendation_type_index != len(self.recommendation_types):
Expand All @@ -164,11 +161,7 @@ def _display(self):
]
if self.recommendation_type_index == 0:
for column in recommendation:
print(
"Column '{0}' is constant and will be dropped".format(
column
)
)
print(f"Column '{column}' is constant and will be dropped")
self.recommendation_type_index += 1
self._display()
return
Expand All @@ -184,17 +177,17 @@ def _display(self):
self.recommendation_type_labels[
self.recommendation_type_index
]
)
),
layout=ipywidgets.Layout(display="flex"),
),
layout=ipywidgets.Layout(display="flex"),
)
self.action_list[
self.recommendation_types[self.recommendation_type_index]
] = []
self.column_list = []
self.message_list = []
self.extra_info_list = []
for column in recommendation.keys():
for column in recommendation:
messages = ipywidgets.Label(
recommendation[column]["Message"],
layout=ipywidgets.Layout(
Expand Down Expand Up @@ -240,9 +233,7 @@ def _display(self):
self.column_list.append(
ipywidgets.Label(
column
+ "(type: {0})".format(
self.ds.sampled_df[column].dtype
),
+ f"(type: {self.ds.sampled_df[column].dtype})",
layout=ipywidgets.Layout(flex="auto"),
color="grey",
)
Expand Down
25 changes: 9 additions & 16 deletions ads/opctl/operator/lowcode/pii/model/report.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
# Copyright (c) 2023, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/


Expand Down Expand Up @@ -123,7 +123,6 @@ def make_model_card(model_name="", readme_path=""):
)
return rc.Group(
rc.Text("-"),
columns=1,
)

try:
Expand Down Expand Up @@ -156,7 +155,6 @@ def make_model_card(model_name="", readme_path=""):
return rc.Group(
rc.Text(text),
eval_res_tb,
columns=2,
)


Expand Down Expand Up @@ -216,7 +214,7 @@ def build_entity_df(entites, id) -> pd.DataFrame:
"Type": "-",
"Redacted To": "-",
}
df = df.append(df2, ignore_index=True)
df = pd.concat([df, pd.DataFrame([df2])], ignore_index=True)
return df


Expand All @@ -232,7 +230,6 @@ def build_report(self) -> rc.Group:
self._make_stats_card(),
self._make_text_card(),
],
type=rc.SelectType.TABS,
),
label="Row Id: " + str(self.spec.id),
)
Expand All @@ -256,7 +253,7 @@ def _make_stats_card(self):
index=True,
)
)
return rc.Group(stats, label="STATS")
return rc.Group(*stats, label="STATS")

def _make_text_card(self):
annotations = []
Expand All @@ -277,7 +274,7 @@ def _make_text_card(self):
},
return_html=True,
)
return rc.Group(rc.HTML(render_html), label="TEXT")
return rc.Group(rc.Html(render_html), label="TEXT")


class PIIOperatorReport:
Expand All @@ -292,7 +289,7 @@ def __init__(self, report_spec: PiiReportSpec, report_uri: str):
RowReportFields(r, report_spec.run_summary.show_sensitive_info)
for r in rows
]

self.report_sections = None
self.report_uri = report_uri

def make_view(self):
Expand All @@ -317,7 +314,6 @@ def make_view(self):
label="Details",
),
],
type=rc.SelectType.TABS,
)
)
self.report_sections = [title_text, report_description, time_proceed, structure]
Expand All @@ -331,7 +327,8 @@ def save_report(
disable_print()
with rc.ReportCreator("My Report") as report:
report.save(
rc.Block(report_sections or self.report_sections), report_local_path
rc.Block(*(report_sections or self.report_sections)),
report_local_path,
)
enable_print()

Expand All @@ -354,7 +351,6 @@ def _build_summary_page(self):
self._make_yaml_card(),
self._make_model_card(),
],
type=rc.SelectType.TABS,
),
)

Expand All @@ -367,7 +363,6 @@ def _build_details_page(self):
blocks=[
row.build_report() for row in self.rows_details
], # RowReportFields
type=rc.SelectType.DROPDOWN,
label="Details",
),
)
Expand Down Expand Up @@ -414,7 +409,6 @@ def _make_summary_stats_card(self) -> rc.Group:
self.report_spec.run_summary.elapsed_time
),
),
columns=2,
),
rc.Heading("Entities Distribution", level=3),
plot_pie(self.report_spec.run_summary.statics),
Expand All @@ -423,7 +417,7 @@ def _make_summary_stats_card(self) -> rc.Group:
entites_df = self._build_total_entity_df()
summary_stats.append(rc.Heading("Resolved Entities", level=3))
summary_stats.append(rc.DataTable(entites_df, index=True))
return rc.Group(summary_stats, label="STATS")
return rc.Group(*summary_stats, label="STATS")

def _make_yaml_card(self) -> rc.Group:
"""Shows the full pii config yaml."""
Expand All @@ -449,13 +443,12 @@ def _make_model_card(self) -> rc.Group:

if len(model_cards) <= 1:
return rc.Group(
model_cards,
*model_cards,
label="MODEL CARD",
)
return rc.Group(
rc.Select(
model_cards,
type=rc.SelectType.TABS,
),
label="MODEL CARD",
)
Expand Down