Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pnria Projet Deeplever
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PNRIA
Global Helper
Pnria Projet Deeplever
Commits
38025bc8
Commit
38025bc8
authored
3 years ago
by
Caroline DE POURTALES
Browse files
Options
Downloads
Patches
Plain Diff
adding alerts
parent
b52d4b73
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
callbacks.py
+62
-56
62 additions, 56 deletions
callbacks.py
with
62 additions
and
56 deletions
callbacks.py
+
62
−
56
View file @
38025bc8
import
dash
from
dash.dependencies
import
Input
,
Output
,
State
from
dash.exceptions
import
PreventUpdate
import
dash_bootstrap_components
as
dbc
from
dash
import
Input
,
Output
,
State
,
html
...
...
@@ -13,10 +12,16 @@ sys.modules['xrf'] = xrf
####### Creates alerts when callback fails #########
alert
_selection_model
=
html
.
Div
([
dbc
.
Alert
(
"
You didn
'
t choose a king of Machine Learning model first.
.
"
,
warning
_selection_model
=
html
.
Div
([
dbc
.
Alert
(
"
You didn
'
t choose a king of Machine Learning model first.
"
,
is_open
=
True
,
color
=
'
warning
'
,
duration
=
10000
,
),
])
warning_selection_pretrained_model
=
html
.
Div
([
dbc
.
Alert
(
"
You uploaded the data, now upload the pretrained model.
"
,
is_open
=
True
,
color
=
'
warning
'
,
duration
=
10000
,
),
])
alert_network
=
html
.
Div
([
dbc
.
Alert
(
"
There was a problem while computing the graph, read the documentation.
\
You might have forgotten to upload the data for Random Forest or you tried to upload an unknown format.
"
,
is_open
=
True
,
...
...
@@ -120,89 +125,90 @@ def register_callbacks(page_home, page_course, page_application, app):
model_application
.
update_ml_model
(
value_ml_model
)
return
None
,
None
# Choice of information for the model - data, feature mapping ...
elif
ihm_id
==
'
model_info_choice
'
:
try
:
model_info
=
parse_contents_data
(
model_info
,
model_info_filename
)
model_application
.
model_info
=
model_info
if
model_application
.
ml_model
is
None
:
return
warning_selection_model
,
None
model_application
.
update_pretrained_model_layout_with_info
(
model_info
,
model_info_filename
)
return
model_application
.
component
.
network
,
None
except
:
return
warning_selection_pretrained_model
,
None
# Choice of pkl pretrained model
elif
ihm_id
==
'
ml_pretrained_model_choice
'
:
if
model_application
.
ml_model
is
None
:
return
alert_selection_model
,
None
else
:
try
:
graph
=
parse_contents_graph
(
pretrained_model_contents
,
pretrained_model_filename
)
model_application
.
update_pretrained_model
(
graph
)
if
not
model_application
.
add_info
:
model_application
.
update_pretrained_model_layout
()
return
model_application
.
component
.
network
,
None
else
:
if
model_application
.
model_info
is
None
:
return
alert_network
,
None
else
:
model_application
.
update_pretrained_model_layout_with_info
(
model_application
.
model_info
,
model_info_filename
)
return
model_application
.
component
.
network
,
None
except
:
return
alert_network
,
None
# Choice of information for the model
elif
ihm_id
==
'
model_info_choice
'
:
model_info
=
parse_contents_data
(
model_info
,
model_info_filename
)
model_application
.
model_info
=
model_info
if
model_application
.
ml_model
is
None
or
model_application
.
pretrained_model
is
None
:
raise
PreventUpdate
model_application
.
update_pretrained_model_layout_with_info
(
model_info
,
model_info_filename
)
return
model_application
.
component
.
network
,
None
try
:
graph
=
parse_contents_graph
(
pretrained_model_contents
,
pretrained_model_filename
)
model_application
.
update_pretrained_model
(
graph
)
if
not
model_application
.
add_info
:
model_application
.
update_pretrained_model_layout
()
return
model_application
.
component
.
network
,
None
else
:
model_application
.
update_pretrained_model_layout_with_info
(
model_application
.
model_info
,
model_info_filename
)
return
model_application
.
component
.
network
,
None
except
:
return
alert_network
,
None
# Choice of instance to explain
elif
ihm_id
==
'
ml_instance_choice
'
:
if
model_application
.
ml_model
is
None
or
model_application
.
pretrained_model
is
None
or
model_application
.
enum
<=
0
or
model_application
.
xtype
is
None
:
raise
PreventUpdate
try
:
instance
=
parse_contents_instance
(
instance_contents
,
instance_filename
)
model_application
.
update_instance
(
instance
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
except
:
return
alert_
network
,
alert_explanation
return
model_application
.
component
.
network
,
alert_explanation
# Choice of number of expls
elif
ihm_id
==
'
number_explanations
'
:
if
model_application
.
ml_model
is
None
or
model_application
.
pretrained_model
is
None
or
model_application
.
instance
is
None
or
model_application
.
solver
is
None
or
model_application
.
xtype
is
None
:
raise
PreventUpdate
model_application
.
update_enum
(
enum
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
try
:
model_application
.
update_enum
(
enum
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
except
:
return
model_application
.
component
.
network
,
alert_explanation
# Choice of AxP or CxP
elif
ihm_id
==
'
explanation_type
'
:
if
model_application
.
ml_model
is
None
or
model_application
.
pretrained_model
is
None
or
model_application
.
instance
is
None
or
model_application
.
enum
<=
0
or
model_application
.
solver
is
None
:
raise
PreventUpdate
model_application
.
update_xtype
(
xtype
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
try
:
model_application
.
update_xtype
(
xtype
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
except
:
return
model_application
.
component
.
network
,
alert_explanation
# Choice of solver
elif
ihm_id
==
'
solver_sat
'
:
if
model_application
.
ml_model
is
None
or
model_application
.
pretrained_model
is
None
or
model_application
.
instance
is
None
or
model_application
.
enum
<=
0
or
model_application
.
xtype
is
None
:
raise
PreventUpdate
model_application
.
update_solver
(
solver
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
try
:
model_application
.
update_solver
(
solver
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
except
:
return
model_application
.
component
.
network
,
alert_explanation
# Choice of AxP to draw
elif
ihm_id
==
'
expl_choice
'
:
if
model_application
.
ml_model
is
None
or
model_application
.
pretrained_model
is
None
or
model_application
.
instance
is
None
or
model_application
.
enum
<=
0
or
model_application
.
xtype
is
None
:
raise
PreventUpdate
model_application
.
update_expl
(
expl_choice
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
try
:
model_application
.
update_expl
(
expl_choice
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
except
:
return
model_application
.
component
.
network
,
alert_explanation
# Choice of CxP to draw
elif
ihm_id
==
'
cont_expl_choice
'
:
if
model_application
.
ml_model
is
None
or
model_application
.
pretrained_model
is
None
or
model_application
.
instance
is
None
or
model_application
.
enum
<=
0
or
model_application
.
xtype
is
None
:
raise
PreventUpdate
model_application
.
update_cont_expl
(
cont_expl_choice
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
try
:
model_application
.
update_cont_expl
(
cont_expl_choice
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
except
:
return
model_application
.
component
.
network
,
alert_explanation
# In the case of RandomForest, id of tree to choose to draw tree
elif
ihm_id
==
'
choice_tree
'
:
if
model_application
.
ml_model
is
None
or
model_application
.
pretrained_model
is
None
:
raise
PreventUpdate
model_application
.
update_tree_to_plot
(
id_tree
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
try
:
model_application
.
update_tree_to_plot
(
id_tree
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
except
:
return
model_application
.
component
.
network
,
alert_explanation
@app.callback
(
Output
(
'
explanation
'
,
'
hidden
'
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment