Example #1
0
def generate_analyze_grid(show_imbalance_selectmultiple, show_imbalance_button,
                          correlations_dendogram_button,
                          correlations_matrix_button) -> GridBox:

    return GridBox(
        children=[
            Label(layout=Layout(width='auto', height='auto'),
                  value='Features to analyze: '),
            Button(layout=Layout(width='auto', height='auto'),
                   disabled=True,
                   style=ButtonStyle(button_color='white')),
            Button(layout=Layout(width='auto', height='auto'),
                   disabled=True,
                   style=ButtonStyle(button_color='white')),
            show_imbalance_selectmultiple,
            Button(layout=Layout(width='auto', height='auto'),
                   disabled=True,
                   style=ButtonStyle(button_color='white')),
            Button(layout=Layout(width='auto', height='auto'),
                   disabled=True,
                   style=ButtonStyle(button_color='white')),
            show_imbalance_button, correlations_dendogram_button,
            correlations_matrix_button
        ],
        layout=Layout(
            width='auto',
            grid_template_columns='33% 33% 33%',
            align_items='center',
            # grid_template_columns='auto auto auto',
            # grid_template_rows='auto auto auto',
            grid_gap='2px 1px'))
Example #2
0
def generate_reset_strip_hbox(on_click_reset_button):

    children = []

    reset_button = widgets.Button(
        disabled=False,
        style=ButtonStyle(button_color='gray'),
        tooltip='Reset the dataset to its initial state',
        icon='undo',
        layout=Layout(width='auto', height='auto'))
    reset_button.on_click(on_click_reset_button)
    children.append(reset_button)
    stripped_columns_label = Label(layout=Layout(width='auto', height='auto'),
                                   value='Stripped columns for the dataset: ')
    children.append(stripped_columns_label)

    return HBox(
        children=children,
        layout=Layout(
            width='auto',
            grid_template_columns="50% 50%",
            align_items='center',
            # grid_template_columns='auto auto auto',
            grid_template_rows='auto',
            grid_gap='3px 3px'))
 def create_first_button(content_type, icon_type):
     if content_type == MFTViewHelper.content_type_folders:
         tooltip = 'Click to get lists of the subfolders and files under this folder'
     elif content_type == MFTViewHelper.content_type_files:
         tooltip = 'Click to get details of the file'
     elif content_type == MFTViewHelper.content_type_breadcrumb:
         tooltip = 'Click to go back to the folder' 
     
     return widgets.Button(description=content_type + ' :', \
                           disabled=True, \
                           layout=Layout(width='auto', height='27px'), \
                           icon=icon_type, \
                           style=ButtonStyle(align_content='center', font_weight='bold'), \
                           tooltip = tooltip)
Example #4
0
def get_details(name):
    if name == 'Q1':
        color = 'SpringGreen'
    elif name == 'Q2':
        color = 'tomato'
    elif name == 'q1':
        color = 'HoneyDew'
        name = ' '
    elif name == 'q2':
        color = 'MistyRose'
        name = ' '
    elif name == 'X':
        color = 'black'
    else:
        color = 'Lavender'
    style = ButtonStyle(button_color=color)
    return name, style
Example #5
0
def gen_keyboard(sample_type=None, base_tone=None):

    if base_tone == "c3":
        num = 3
    elif base_tone == "c4":
        num = 4
    elif base_tone == "c5":
        num = 5
    else:
        raise AssertionError(
            "Make sure you have choose one \x1b[31mbase_tone\x1b[0m!")

    if sample_type == "src":
        Type = "src"
    elif sample_type == "tgt":
        Type = "tgt"
    else:
        raise AssertionError(
            "Make sure you have choose one \x1b[31msample type\x1b[0m!")

    print(
        "\x1b[31mNOTE\x1b[0m: You have to enter enough notes in order to have your own samples!"
    )

    items_black = [
        Button(description='',
               layout=Layout(flex='0.8 1 5%', height='100px', min_width='5px'),
               button_style='danger',
               style=ButtonStyle(button_color='white')),
        Button(description='C#{}'.format(num),
               layout=Layout(flex='1 1 auto', height='100px',
                             min_width='10px'),
               button_style='danger',
               style=ButtonStyle(button_color='black')),
        Button(description='D#{}'.format(num),
               layout=Layout(flex='1 1 auto', height='100px',
                             min_width='10px'),
               button_style='danger',
               style=ButtonStyle(button_color='black')),
        Button(description='',
               layout=Layout(flex='0.8 22%', height='100px', min_width='20px'),
               button_style='danger',
               style=ButtonStyle(button_color='white')),
        Button(description='F#{}'.format(num),
               layout=Layout(flex='1 1 auto', height='100px',
                             min_width='10px'),
               button_style='danger',
               style=ButtonStyle(button_color='black')),
        Button(description='G#{}'.format(num),
               layout=Layout(flex='1 1 auto', height='100px',
                             min_width='10px'),
               button_style='danger',
               style=ButtonStyle(button_color='black')),
        Button(description='A#{}'.format(num),
               layout=Layout(flex='1 1 auto', height='100px',
                             min_width='10px'),
               button_style='danger',
               style=ButtonStyle(button_color='black')),
        Button(description='',
               layout=Layout(flex='1 1 60%', height='100px', min_width='32px'),
               button_style='danger',
               style=ButtonStyle(button_color='white')),
    ]

    items_white = [
        Button(description='C{}'.format(num),
               layout=Layout(flex='1 1 10%',
                             height='100px',
                             min_width='10px',
                             border='2px solid'),
               style=ButtonStyle(button_color='white')),
        Button(description='D{}'.format(num),
               layout=Layout(flex='1 1 10%',
                             height='100px',
                             min_width='10px',
                             border='2px solid'),
               style=ButtonStyle(button_color='white')),
        Button(description='E{}'.format(num),
               layout=Layout(flex='1 1 10%',
                             height='100px',
                             min_width='10px',
                             border='2px solid'),
               style=ButtonStyle(button_color='white')),
        Button(description='F{}'.format(num),
               layout=Layout(flex='1 1 10%',
                             height='100px',
                             min_width='10px',
                             border='2px solid'),
               style=ButtonStyle(button_color='white')),
        Button(description='G{}'.format(num),
               layout=Layout(flex='1 1 10%',
                             height='100px',
                             min_width='10px',
                             border='2px solid'),
               style=ButtonStyle(button_color='white')),
        Button(description='A{}'.format(num),
               layout=Layout(flex='1 1 10%',
                             height='100px',
                             min_width='10px',
                             border='2px solid'),
               style=ButtonStyle(button_color='white')),
        Button(description='B{}'.format(num),
               layout=Layout(flex='1 1 10%',
                             height='100px',
                             min_width='10px',
                             border='2px solid'),
               style=ButtonStyle(button_color='white')),
        Button(description='C{}'.format(num + 1),
               layout=Layout(flex='1 1 10%',
                             height='100px',
                             min_width='10px',
                             border='2px solid'),
               style=ButtonStyle(button_color='white')),
    ]

    items_note = [note_style]

    item_restart = [
        Button(description="Restart the recording",
               button_style='warning',
               layout=Layout(flex='1 1 auto', height='28px', min_width='10px'))
    ]

    item_delete = [
        Button(description="Delete the last recording",
               button_style='danger',
               layout=Layout(flex='1 1 auto', height='28px', min_width='10px'))
    ]

    item_play = [
        Button(description="Play the recording",
               button_style='success',
               layout=Layout(flex='1 1 auto', height='28px', min_width='10px'))
    ]

    # part where perform button
    restart = item_restart[0]
    delete = item_delete[0]
    play = item_play[0]

    if Type == "src":
        for white in items_white:
            white.on_click(src_clicked)

        for black in items_black:
            if "#" in black.description:
                black.on_click(src_clicked)

        restart.on_click(src_reset)
        delete.on_click(src_delete)
        play.on_click(src_play)

    else:
        for white in items_white:
            white.on_click(tgt_clicked)

        for black in items_black:
            if "#" in black.description:
                black.on_click(tgt_clicked)

        restart.on_click(tgt_reset)
        delete.on_click(tgt_delete)
        play.on_click(tgt_play)

    box_layout = Layout(display='flex',
                        flex_flow='row',
                        align_items='stretch',
                        width='40%',
                        grid_gap="")
    box_play = Box(children=item_play, layout=box_layout)
    box_restart = Box(children=item_restart, layout=box_layout)
    box_delete = Box(children=item_delete, layout=box_layout)
    box_black = Box(children=items_black, layout=box_layout)
    box_white = Box(children=items_white, layout=box_layout)
    box_note = Box(children=items_note, layout=box_layout)
    display(
        VBox([
            box_play, box_restart, box_delete, box_black, box_white, box_note
        ]))
Example #6
0
    def toExploration(self, event=None):
        reload = self.showPanel("Exploration")
        if reload:
            self.ui["Exploration"]["grid"].children = []
            main_dimensions = []
            secondary_dimensions = []
            for k in self.ui["Filters"]["grid"].get_changed_df().columns:
                if "input" in k:
                    main_dimensions.append(
                        Checkbox(value=True,
                                 description=k,
                                 layout=Layout(width="auto")))
                else:
                    main_dimensions.append(
                        Checkbox(value=False,
                                 description=k,
                                 layout=Layout(width="auto")))
                secondary_dimensions.append(
                    Checkbox(value=True,
                             description=k,
                             layout=Layout(width="auto")))
            self.ui["Exploration"]["main_dimensions"] = main_dimensions
            self.ui["Exploration"]["main_plot"] = Dropdown(
                description="Visualization",
                options=[
                    "sankey", "pca", "sankeytree", "sunburst", "parallelscat",
                    "scattermatrix"
                ],
                value="sankey")
            self.ui["Exploration"][
                "secondary_dimensions"] = secondary_dimensions
            self.ui["Exploration"]["secondary_plot1"] = Dropdown(
                description="Visualization",
                options=[
                    "table", "corrcoef", "sankey", "pca", "sankeytree",
                    "sunburst", "parallelscat", "parallels", "scattermatrix"
                ],
                value="corrcoef")
            self.ui["Exploration"]["secondary_plot2"] = Dropdown(
                description="Visualization",
                options=[
                    "table", "corrcoef", "sankey", "pca", "sankeytree",
                    "sunburst", "parallelscat", "parallels", "scattermatrix"
                ],
                value="table")
            vb1 = VBox(main_dimensions,
                       layout=Layout(width="100%", padding="10px"))

            vb1 = GridBox(layout=Layout(
                width='auto',
                grid_template_columns='auto auto auto',
                grid_template_rows=" ".join([
                    'auto' for i in self.ui["Exploration"]["main_dimensions"]
                ]),
                grid_gap='1px 1px'))
            children = []
            for i, w in enumerate(self.ui["Exploration"]["main_dimensions"]):
                children.append(w)
                up = Button(icon="angle-up", layout=Layout(width="50px"))
                up.on_click(
                    lambda b, this=self, pos=i, w=vb1, l="main_dimensions":
                    this.moveOption(pos, True, w, l))
                children.append(up)
                down = Button(icon="angle-down", layout=Layout(width="50px"))
                down.on_click(
                    lambda b, this=self, pos=i, w=vb1, l="main_dimensions":
                    this.moveOption(pos, False, w, l))
                children.append(down)
            vb1.children = children

            vb2 = GridBox(layout=Layout(width='auto',
                                        grid_template_columns='auto auto auto',
                                        grid_template_rows=" ".join([
                                            'auto'
                                            for i in self.ui["Exploration"]
                                            ["secondary_dimensions"]
                                        ]),
                                        grid_gap='1px 1px'))
            children = []
            for i, w in enumerate(
                    self.ui["Exploration"]["secondary_dimensions"]):
                children.append(w)
                up = Button(icon="angle-up", layout=Layout(width="50px"))
                up.on_click(
                    lambda b, this=self, pos=i, w=vb2, l=
                    "secondary_dimensions": this.moveOption(pos, True, w, l))
                children.append(up)
                down = Button(icon="angle-down", layout=Layout(width="50px"))
                down.on_click(
                    lambda b, this=self, pos=i, w=vb2, l=
                    "secondary_dimensions": this.moveOption(pos, False, w, l))
                children.append(down)
            vb2.children = children

            self.ui["Exploration"]["grid"].children = [
                VBox([
                    Button(description="Main Dimensions",
                           layout=Layout(width='auto'),
                           style=ButtonStyle(button_color='lightblue')),
                    self.ui["Exploration"]["main_plot"],
                    vb1,
                ],
                     layout=Layout(width="50%")),
                VBox([
                    Button(description="Secondary Dimensions",
                           layout=Layout(width='auto'),
                           style=ButtonStyle(button_color='lightblue')),
                    self.ui["Exploration"]["secondary_plot1"],
                    self.ui["Exploration"]["secondary_plot2"],
                    vb2,
                ],
                     layout=Layout(width="50%"))
            ]
 def define_button_style(button_type):
     if button_type == MFTViewHelper.button_type_content:
         return ButtonStyle(button_color='#FFF', font_color='blue')
     elif button_type == MFTViewHelper.button_type_navigator:
         return ButtonStyle(button_color='#d0d0ff')
Example #8
0
 def define_button_style(self):
     return ButtonStyle(button_color='#FFF', font_color='blue')
Example #9
0
def add_dummy_widgets(min_number, children, number_of_models):
    for i in range(min_number - number_of_models):
        children.append(
            Button(layout=Layout(width='auto', height='auto'),
                   disabled=True,
                   style=ButtonStyle(button_color='white')))
Example #10
0
    def annotate(self):
        '''Displays texts to be annotated in a UI. Loads user inputted labels and timestamps into
            ``annotations`` dataframe.
        '''
        try:
            with open(logo_path, 'rb') as image_file:
                image = image_file.read()
                logo = Image(value=image, format='png', width='40%')

        except:
            logo = HTML('<h1>t &nbsp; <span style="color:#36a849">o</span> \
            &nbsp; r &nbsp; t &nbsp; u &nbsp; s</h1>')

        rules = HTML(
            'Click on the label corresponding with the text below. Each selection requires \
                confirmation before proceeding to the next item.')
        annotation_text = self.subset_df.iloc[self.annotation_index, -1]
        html = self.make_html(annotation_text)
        text = HTML(html)

        labels = []
        for label in self.labels:
            label_button = Button(description=label,
                                  layout=Layout(border='solid',
                                                flex='1 1 auto',
                                                width='auto'),
                                  style=ButtonStyle(button_color='#eeeeee',
                                                    font_weight='bold'))
            labels.append(label_button)

        label_buttons = HBox(labels)

        skip_button = Button(description='Skip',
                             layout=Layout(border='solid',
                                           flex='1 1 auto',
                                           width='auto'),
                             style=ButtonStyle(button_color='#eeeeee',
                                               font_weight='bold'))

        confirm_button = Button(description='Confirm selection',
                                layout=Layout(border='solid',
                                              flex='1 1 auto',
                                              width='auto',
                                              grid_area='confirm'),
                                style=ButtonStyle(button_color='#eeeeee',
                                                  font_weight='bold'))

        redo_button = Button(description='Try again',
                             layout=Layout(border='solid',
                                           flex='1 1 auto',
                                           width='auto',
                                           grid_area='redo'),
                             style=ButtonStyle(button_color='#eeeeee',
                                               font_weight='bold'))

        progress_bar = IntProgress(
            value=self.annotation_index,
            min=0,
            max=self.num_records,
            step=1,
            description=f'{self.annotation_index + 1}/{self.num_records}',
            bar_style='',
            orientation='horizontal',
            layout=Layout(width='50%', align_self='flex-end'))
        progress_bar.style.bar_color = '#36a849'

        header = HBox([logo, progress_bar])
        sentiment_buttons = HBox([label_buttons, skip_button])
        sentiment = labels + [skip_button]
        confirm = [confirm_button, redo_button]

        box_layout = Layout(display='flex',
                            flex_flow='row',
                            align_items='stretch',
                            width='100%')

        box_sentiment = Box(sentiment, layout=box_layout)
        box_confirm = Box(confirm, layout=box_layout)

        all_buttons = VBox([box_sentiment, box_confirm],
                           layout=Layout(width='auto',
                                         grid_area='all_buttons'))

        ui = GridBox(children=[all_buttons],
                     layout=Layout(width='100%',
                                   grid_template_rows='auto auto',
                                   grid_template_columns='15% 70% 15%',
                                   grid_template_areas='''
                ". all_buttons ."
                '''))

        output = Output()

        display(header, rules, text, ui, output)
        confirm_button.layout.visibility = 'hidden'
        redo_button.layout.visibility = 'hidden'

        def label_buttons_clicked(button):
            '''Response to button click of any sentiment buttons.
            
            Appends ``annotations`` with label selection.
            :param button: Label buttons click. 
            '''
            button.style.button_color = '#36a849'
            record_id = self.create_record_id()
            self.annotations.loc[len(self.annotations)] = [
                record_id[self.annotation_index],
                self.subset_df[self.text].iloc[self.annotation_index],
                str(button.description).lower(),
                datetime.now().replace(microsecond=0)
            ]

            for label in labels:
                label.disabled = True
                if button != label:
                    label.layout.border = 'None'

            skip_button.disabled = True
            skip_button.layout.border = 'None'

            with output:
                clear_output(True)
                sentiment_buttons.layout.visibility = 'visible'
                confirm_button.layout.visibility = 'visible'
                redo_button.layout.visibility = 'visible'

        for label in labels:
            label.on_click(label_buttons_clicked)

        def skip_button_clicked(button):
            '''Response to button click of the skip button.

            Appends ``annotations``. Label value is ``Null``.
            
            :param button: Skip button click.
            '''
            button.style.button_color = '#36a849'
            record_id = self.create_record_id()
            self.annotations.loc[len(self.annotations)] = [
                record_id[self.annotation_index],
                self.subset_df[self.text].iloc[self.annotation_index], None,
                datetime.now().replace(microsecond=0)
            ]
            for label in labels:
                label.disabled = True
                label.layout.border = 'None'

            skip_button.disabled = True

            with output:
                clear_output(True)
                sentiment_buttons.layout.visibility = 'visible'
                confirm_button.layout.visibility = 'visible'
                redo_button.layout.visibility = 'visible'

        skip_button.on_click(skip_button_clicked)

        def confirm_button_clicked(button):
            '''Response to click of the confirm button.

            Advances the ``annotation_index`` to view the next item in the annotation tool.
                Indicates the tool is done if ``annotation_index`` does not advance further.
            
            :param button: Confirmation button click.
            '''
            if self.annotation_index < len(self.subset_df) - 1:
                self.annotation_index += 1
                clear_output(True)
                self.annotate()
            else:

                clear_output(True)
                progress_bar.value = self.num_records
                progress_bar.description = 'Complete'
                display(header, output)

        confirm_button.on_click(confirm_button_clicked)

        def redo_button_clicked(button):
            '''Response to click of the redo button.

            Deletes the most recent input to ``annotations``.
            
            :param button: Redo button click.
            '''
            self.annotations = self.annotations.head(-1)
            for label in labels:
                label.style.button_color = '#eeeeee'
                label.disabled = False
                label.layout.border = 'solid'

            skip_button.style.button_color = '#eeeeee'
            skip_button.disabled = False
            skip_button.layout.border = 'solid'

            with output:
                clear_output(True)
                sentiment_buttons.layout.visibility = 'visible'
                confirm_button.layout.visibility = 'hidden'
                redo_button.layout.visibility = 'hidden'

        redo_button.on_click(redo_button_clicked)
 def define_button_style():
     """ define button style """
     return ButtonStyle(button_color='#FFF', font_color='blue')