2
2
# pylint: disable = too-few-public-methods, wrong-import-order, protected-access, cell-var-from-loop
3
3
# pylint: disable = too-many-instance-attributes, import-error. too-many-locals
4
4
# pylint: disable = consider-using-f-string
5
+ import os
6
+ import tempfile
7
+
5
8
import numpy as np
6
9
import pandas as pd
7
10
from bokeh .io import show , output_file , output_notebook , reset_output
@@ -110,13 +113,20 @@ def __init__(
110
113
The set of background datapoints as a: {}
111
114
Keyword Arguments:
112
115
* 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
114
117
dashboard, as a float between 0 and 1. Choose a larger number to see more,
115
118
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
118
121
Jupyter notebook. If false, the visualizations will be saved as HTML and opened
119
122
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.
120
130
"""
121
131
self .model = model
122
132
self .inputs = one_input_convert (inputs )
@@ -131,7 +141,17 @@ def __init__(
131
141
if self .notebook :
132
142
output_notebook ()
133
143
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
+ )
135
155
136
156
self .cfdict = None
137
157
self .shap_saliencies = None
0 commit comments