<commit_before>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from ipywidgets import interact_manual, interact
from ipywidgets import Button, HBox, IntText, HTML, VBox
from IPython.display import display, clear_output
import os.path as op


def load_data(projects_path='../projets'):
    "Loads presidential candidates data."
    mlp = pd.read_csv(op.join(projects_path, 'marine_le_pen.csv'))
    mlp['proposition'].str.replace('^.\s', '')
    bh = pd.read_csv(op.join(projects_path, 'benoit_hamon.csv'))
    jlm = pd.read_csv(op.join(projects_path, 'jean_luc_melenchon.csv'))
    jlm['proposition'].dropna().str.replace("Nous proposons de réaliser les mesures suivantes\xa0:", '').replace('\xa0', '  ')
    em = pd.read_csv(op.join(projects_path, 'emmanuel_macron.csv'))
    ff = pd.read_csv(op.join(projects_path, 'francois_fillon.csv'))
    nda = pd.read_csv(op.join(projects_path, 'nicolas_dupont-aignan.csv'))
    candidates = [jlm, bh, em, ff, nda, mlp]
    candidate_labels = ['JLM', 'BH', 'EM', 'FF', 'NDA', 'MLP']
    return candidates, candidate_labels


class GUI:
    def __init__(self, candidate_labels, propositions):
        # internal vars
        self.header = '<p style="font-size: 150%;font-weight: 300;line-height: 1.39;margin: 0 0 12.5px;">{} <a target="_blank" href="{}">source</a></p>'
        self.candidate_labels = candidate_labels
        self.propositions = propositions
        self.choice = None
        self.clicked = dict(zip(self.candidate_labels, [False] * len(self.candidate_labels)))
        self.confusion_matrix = np.zeros((len(candidate_labels), len(candidate_labels)))
        
        # candidate buttons
        buttons = [Button(description=label) for label in self.candidate_labels]
        for b in buttons:
            b.on_click(self.on_button_clicked)
        hbox1 = HBox()
        hbox1.children = buttons
        self.buttons = buttons

        # scorebox and new_question button and confusion matrix
        self.scorebox = IntText(description='score', value=0)
        new_question = Button(description='nouvelle question !')
        new_question.on_click(self.create_new_question)
        confusion_matrix_button = Button(description='afficher matrice de confusion')
        confusion_matrix_button.on_click(self.show_confusion_matrix)
        hbox2 = HBox()
        hbox2.children = [self.scorebox, new_question, confusion_matrix_button]

        # proposition box
        self.html = HTML()

        # general layout
        vbox = VBox()
        vbox.children = [hbox1, hbox2, self.html]
        self.box = vbox

        # generate first question
        self.create_new_question()
        
    def create_new_question(self, b=None):
        clear_output()<commit_msg>disabled score button<commit_after>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from ipywidgets import Button, HBox, IntText, HTML, VBox
from IPython.display import display, clear_output
import os.path as op


def load_data(projects_path='../projets'):
    "Loads presidential candidates data."
    mlp = pd.read_csv(op.join(projects_path, 'marine_le_pen.csv'))
    mlp['proposition'].str.replace('^.\s', '')
    bh = pd.read_csv(op.join(projects_path, 'benoit_hamon.csv'))
    jlm = pd.read_csv(op.join(projects_path, 'jean_luc_melenchon.csv'))
    jlm['proposition'].dropna().str.replace("Nous proposons de réaliser les mesures suivantes\xa0:", '').replace('\xa0', '  ')
    em = pd.read_csv(op.join(projects_path, 'emmanuel_macron.csv'))
    ff = pd.read_csv(op.join(projects_path, 'francois_fillon.csv'))
    nda = pd.read_csv(op.join(projects_path, 'nicolas_dupont-aignan.csv'))
    candidates = [jlm, bh, em, ff, nda, mlp]
    candidate_labels = ['JLM', 'BH', 'EM', 'FF', 'NDA', 'MLP']
    return candidates, candidate_labels


class GUI:
    def __init__(self, candidate_labels, propositions):
        # internal vars
        self.header = '<p style="font-size: 150%;font-weight: 300;line-height: 1.39;margin: 0 0 12.5px;">{} <a target="_blank" href="{}">source</a></p>'
        self.candidate_labels = candidate_labels
        self.propositions = propositions
        self.choice = None
        self.clicked = dict(zip(self.candidate_labels, [False] * len(self.candidate_labels)))
        self.confusion_matrix = np.zeros((len(candidate_labels), len(candidate_labels)))
        
        # candidate buttons
        buttons = [Button(description=label) for label in self.candidate_labels]
        for b in buttons:
            b.on_click(self.on_button_clicked)
        hbox1 = HBox()
        hbox1.children = buttons
        self.buttons = buttons

        # scorebox and new_question button and confusion matrix
        self.scorebox = IntText(description='score', value=0, disabled=True)
        new_question = Button(description='nouvelle question !')
        new_question.on_click(self.create_new_question)
        confusion_matrix_button = Button(description='afficher matrice de confusion')
        confusion_matrix_button.on_click(self.show_confusion_matrix)
        hbox2 = HBox()
        hbox2.children = [self.scorebox, new_question, confusion_matrix_button]

        # proposition box
        self.html = HTML()

        # general layout
        vbox = VBox()
        vbox.children = [hbox1, hbox2, self.html]
        self.box = vbox

        # generate first question
        self.create_new_question()
        
    def create_new_question(self, b=None):
        clear_output()
{'fraction_non_alphanumeric': 0.12189327485380116, 'fraction_numerical': 0.008406432748538011, 'mean_word_length': 3.3819055244195355, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3546991', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1725, 'n_words': 365}