-
Notifications
You must be signed in to change notification settings - Fork 484
Expand file tree
/
Copy pathresponsibleai_dashboard.py
More file actions
148 lines (127 loc) · 5.63 KB
/
Copy pathresponsibleai_dashboard.py
File metadata and controls
148 lines (127 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Copyright (c) Microsoft Corporation
# Licensed under the MIT License.
"""Defines the Model Analysis Dashboard class."""
import json
from flask import jsonify, request
from raiutils.models import ModelTask
from raiwidgets.dashboard import Dashboard
from raiwidgets.responsibleai_dashboard_input import \
ResponsibleAIDashboardInput
from responsibleai import RAIInsights
class ResponsibleAIDashboard(Dashboard):
"""The dashboard class, wraps the dashboard component.
:param analysis: An object that represents an RAIInsights.
:type analysis: RAIInsights
:param public_ip: Optional. If running on a remote vm,
the external public ip address of the VM.
:type public_ip: str
:param port: The port to use on locally hosted service.
:type port: int
:param locale: The language in which user wants to load and access the
ResponsibleAI Dashboard. The default language is english ("en").
:type locale: str
:param cohort_list:
List of cohorts defined by the user for the dashboard.
:type cohort_list: List[Cohort]
:param is_private_link: If the dashboard environment is
a private link AML workspace.
:type is_private_link: bool
"""
def __init__(self, analysis: RAIInsights,
public_ip=None, port=None, locale=None,
cohort_list=None, is_private_link=False,
**kwargs):
self.input = ResponsibleAIDashboardInput(
analysis, cohort_list=cohort_list)
super(ResponsibleAIDashboard, self).__init__(
dashboard_type="ResponsibleAI",
model_data=self.input.dashboard_input,
public_ip=public_ip,
port=port,
locale=locale,
no_inline_dashboard=True,
is_private_link=is_private_link,
**kwargs)
def predict():
data = request.get_json(force=True)
return jsonify(self.input.on_predict(data))
self.add_url_rule(predict, '/predict', methods=["POST"])
if analysis.task_type == ModelTask.FORECASTING:
def forecast():
data = request.get_json(force=True)
return jsonify(self.input.forecast(data))
self.add_url_rule(forecast, '/forecast', methods=["POST"])
else:
def tree():
data = request.get_json(force=True)
return jsonify(self.input.debug_ml(data))
self.add_url_rule(tree, '/tree', methods=["POST"])
def matrix():
data = request.get_json(force=True)
return jsonify(self.input.matrix(data))
self.add_url_rule(matrix, '/matrix', methods=["POST"])
def causal_whatif():
data = request.get_json(force=True)
return jsonify(self.input.causal_whatif(data))
self.add_url_rule(
causal_whatif,
'/causal_whatif',
methods=["POST"])
def global_causal_effects():
data = request.get_json(force=True)
return jsonify(self.input.get_global_causal_effects(data))
self.add_url_rule(
global_causal_effects,
'/global_causal_effects',
methods=["POST"])
def global_causal_policy():
data = request.get_json(force=True)
return jsonify(self.input.get_global_causal_policy(data))
self.add_url_rule(
global_causal_policy,
'/global_causal_policy',
methods=["POST"])
def importances():
return jsonify(self.input.importances())
self.add_url_rule(importances, '/importances', methods=["POST"])
def get_exp():
data = request.get_json(force=True)
return jsonify(self.input.get_exp(data))
self.add_url_rule(get_exp, '/get_exp', methods=["POST"])
def get_object_detection_metrics():
data = request.get_json(force=True)
return jsonify(self.input.get_object_detection_metrics(data))
self.add_url_rule(
get_object_detection_metrics,
'/get_object_detection_metrics',
methods=["POST"]
)
def get_question_answering_metrics():
data = request.get_json(force=True)
return jsonify(self.input.get_question_answering_metrics(data))
self.add_url_rule(
get_question_answering_metrics,
'/get_question_answering_metrics',
methods=["POST"]
)
def get_generative_text_metrics():
data = request.get_json(force=True)
return jsonify(self.input.get_generative_text_metrics(data))
self.add_url_rule(
get_generative_text_metrics,
'/get_generative_text_metrics',
methods=["POST"]
)
if hasattr(self._service, 'socketio'):
@self._service.socketio.on('handle_object_detection_json')
def handle_object_detection_json(od_json):
od_data = json.loads(od_json['data'])
return self.input.get_object_detection_metrics(od_data)
@self._service.socketio.on('handle_question_answering_json')
def handle_question_answering_json(qa_json):
qa_data = json.loads(qa_json['data'])
return self.input.get_question_answering_metrics(qa_data)
@self._service.socketio.on('handle_generative_text_json')
def handle_generative_text_json(gt_json):
gt_data = json.loads(gt_json['data'])
return self.input.get_generative_text_metrics(gt_data)