Skip to content

Commit

Permalink
Fix recipe card display format (#10893)
Browse files Browse the repository at this point in the history
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
  • Loading branch information
WeichenXu123 committed Jan 25, 2024
1 parent b7c0b77 commit c438237
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions mlflow/recipes/cards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,20 @@ def render_table(table, columns=None, hide_index=True):
from pandas.io.formats.style import Styler

if not isinstance(table, Styler):
table = pd.DataFrame(table, columns=columns).style
table = pd.DataFrame(table, columns=columns)
# Escape specific characters in HTML to prevent
# javascript code injection
# Note that `pandas_df.style.to_html(escape=True) does not work
# So that we have to manually escape values in dataframe cells.

def escape_value(x):
return html.escape(str(x))

if hasattr(table, "map"):
table = table.map(escape_value)
else:
table = table.applymap(escape_value)
table = table.style

pandas_version = Version(pd.__version__)

Expand Down Expand Up @@ -290,8 +303,12 @@ def __init__(
'<p><strong>Step status: <span style="color:red">Failed</span></strong></p>',
)
self.add_tab(
"Stacktrace", "<div class='stacktrace-container'>{{ STACKTRACE|e }}</div>"
).add_html("STACKTRACE", f'<p style="margin-top:0px"><code>{failure_traceback}</code></p>')
"Stacktrace",
(
"<div class='stacktrace-container'><p style='margin-top:0px'><code>"
"{{ STACKTRACE|e }}</code></p></div>"
),
).add_html("STACKTRACE", str(failure_traceback))
warning_output_path = os.path.join(output_directory, "warning_logs.txt")
if os.path.exists(warning_output_path):
with open(warning_output_path) as f:
Expand Down
2 changes: 1 addition & 1 deletion mlflow/recipes/steps/ingest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _build_step_card(
)
# Tab #2 -- Ingested dataset schema.
schema_html = BaseCard.render_table(schema["fields"])
card.add_tab("Data Schema", "{{SCHEMA|e}}").add_html("SCHEMA", schema_html)
card.add_tab("Data Schema", "{{SCHEMA}}").add_html("SCHEMA", schema_html)

if data_preview is not None:
# Tab #3 -- Ingested dataset preview.
Expand Down

0 comments on commit c438237

Please sign in to comment.