Skip to content
Snippets Groups Projects
Commit b52d4b73 authored by Caroline DE POURTALES's avatar Caroline DE POURTALES
Browse files

cleaning instances

parent c3433fa9
No related branches found
No related tags found
No related merge requests found
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':
......
......@@ -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([
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment