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
b52d4b73
Commit
b52d4b73
authored
3 years ago
by
Caroline DE POURTALES
Browse files
Options
Downloads
Patches
Plain Diff
cleaning instances
parent
c3433fa9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
callbacks.py
+46
-14
46 additions, 14 deletions
callbacks.py
utils.py
+2
-0
2 additions, 0 deletions
utils.py
with
48 additions
and
14 deletions
callbacks.py
+
46
−
14
View file @
b52d4b73
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
from
utils
import
parse_contents_graph
,
parse_contents_instance
,
parse_contents_data
...
...
@@ -9,6 +11,27 @@ from pages.application.RandomForest.utils.xrf import *
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..
"
,
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
,
color
=
'
danger
'
,
duration
=
10000
,
),
])
alert_explanation
=
html
.
Div
([
dbc
.
Alert
(
"
There was a problem while computing the explanation. Read the documentation to understand which king of format are accepted.
"
,
is_open
=
True
,
color
=
'
danger
'
,
duration
=
10000
,
),
])
alert_version_model
=
[]
######################################################
def
register_callbacks
(
page_home
,
page_course
,
page_application
,
app
):
page_list
=
[
'
home
'
,
'
course
'
,
'
application
'
]
...
...
@@ -100,18 +123,23 @@ def register_callbacks(page_home, page_course, page_application, app):
# Choice of pkl pretrained model
elif
ihm_id
==
'
ml_pretrained_model_choice
'
:
if
model_application
.
ml_model
is
None
:
raise
PreventUpdate
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
return
alert_selection_model
,
None
else
:
if
model_application
.
model_info
is
None
:
raise
PreventUpdate
model_application
.
update_pretrained_model_layout_with_info
(
model_application
.
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
:
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
'
:
...
...
@@ -126,9 +154,13 @@ def register_callbacks(page_home, page_course, page_application, app):
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
instance
=
parse_contents_instance
(
instance_contents
,
instance_filename
)
model_application
.
update_instance
(
instance
)
return
model_application
.
component
.
network
,
model_application
.
component
.
explanation
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
# Choice of number of expls
elif
ihm_id
==
'
number_explanations
'
:
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
2
−
0
View file @
b52d4b73
...
...
@@ -22,6 +22,8 @@ def parse_contents_graph(contents, filename):
data
=
pickle
.
load
(
io
.
BytesIO
(
decoded
))
elif
'
.txt
'
in
filename
:
data
=
decoded
.
decode
(
'
utf-8
'
).
strip
()
elif
'
.dt
'
in
filename
:
data
=
decoded
.
decode
(
'
utf-8
'
).
strip
()
except
Exception
as
e
:
print
(
e
)
return
html
.
Div
([
...
...
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