Capture cell facts
The cell facts feature in the notebook allows direct capturing of cell outputs, such as print statements, tables, and images, and automatically saves them into HTML snippets. These HTML files can be easily uploaded as attachments, appearing as inline-rendered content in the UI, without the need for additional ‘save to file’ statements.
Magic command: %%capture_cell_facts
Important
Using capture_cell_facts magic command on top of any cell captures cell outputs and writes to an html file which can be used to set as attachment under any defined custom facts.
Captured cell facts are written to temp dir
{cur dir}/captured_cell_facts/Captured_Cell_Output.htmlEach cell run output overwrites the previous temp html file of captured cell facts. Each command output is captured as a snippet html.
Two args are supported with the magic command:
-poor--printmsgonly: print statements are only captured from any given cell-ccor--capturecode: capture cell codes with output
In case of any cell mix of print messages and images or tables etc., the command captures everything except messages using
print(). If you want to capture all, usedisplay()in place ofprint()method.Once facts are captured, you can use
`set_cell_attachment_fact()`api to attach the detail to any custom fact id.
- set_cell_attachment_fact(self, description: str, fact_id: str)
Set attachment fact using captured cell output. Supported for CPD version >=4.6.5.
- Parameters:
fact_id (str) – Fact id for the attachment
description (str) – (Optional) Description about the cell facts attachment file
Usage example:
model.set_cell_attachment_fact(description='<file description>', fact_id='<custom fact id>')
Sample
Capture print statements
%%capture_cell_facts -po
# capture print stmt only
print("Working on Iris data")
print("Model trained")
wml_model.set_cell_attachment_fact(description="Print output",fact_id="print_store")
Capture confusion metrix
%%capture_cell_facts
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
predictions1=classifier.predict(x_test)
cm1 = confusion_matrix(y_test, predictions1,labels=classifier.classes_)
disp1 = ConfusionMatrixDisplay(confusion_matrix=cm1,display_labels=classifier.classes_)
disp1.plot()
plt.show()
time.sleep(2)
wml_model.set_cell_attachment_fact(description="Confusion metrix",fact_id="con_metrix_store")