22# pylint: disable = too-few-public-methods, wrong-import-order, protected-access, cell-var-from-loop
33# pylint: disable = too-many-instance-attributes, import-error. too-many-locals
44# pylint: disable = consider-using-f-string
5+ import os
6+ import tempfile
7+
58import numpy as np
69import pandas as pd
710from bokeh .io import show , output_file , output_notebook , reset_output
@@ -110,13 +113,20 @@ def __init__(
110113 The set of background datapoints as a: {}
111114 Keyword Arguments:
112115 * fraction_counterfactuals_to_display : float
113- (Default= 0.1) The fraction of found byproduct counterfactuals to display in the
116+ (default=` 0.1` ) The fraction of found byproduct counterfactuals to display in the
114117 dashboard, as a float between 0 and 1. Choose a larger number to see more,
115118 but this will make plot rendering more expensive.
116- * notebook : bool
117- (Default= False) If true, Tyrus will launch the visualizations inline in a
119+ * notebook : ` bool
120+ (default=` False` ) If true, Tyrus will launch the visualizations inline in a
118121 Jupyter notebook. If false, the visualizations will be saved as HTML and opened
119122 automatically in your default browser.
123+ * filepath : str
124+ (default=`None`) If `notebook==False`, the Tyrus HTML will be generated in
125+ a temporary directory, the path of which can be accessed by `Tyrus.filepath`. Note
126+ that this temporary directory will be *deleted* when the Tyrus object is deleted/
127+ goes out of scope. Passing a value to `filepath` will manually specify the location
128+ which to generate the Tyrus HTML file, which will
129+ remain there after execution is finished.
120130 """
121131 self .model = model
122132 self .inputs = one_input_convert (inputs )
@@ -131,7 +141,17 @@ def __init__(
131141 if self .notebook :
132142 output_notebook ()
133143 else :
134- output_file (filename = "trustyai_dashboard.html" , title = "TrustyAI Dashboard" )
144+ if kwargs .get ("filepath" ) is None :
145+ self .tmp_dir = (
146+ tempfile .TemporaryDirectory () # pylint: disable=consider-using-with
147+ )
148+ self .filepath = self .tmp_dir .name
149+ else :
150+ self .filepath = kwargs ["filepath" ]
151+ output_file (
152+ filename = os .path .join (self .filepath , "trustyai_dashboard.html" ),
153+ title = "TrustyAI Dashboard" ,
154+ )
135155
136156 self .cfdict = None
137157 self .shap_saliencies = None
0 commit comments