Esempio n. 1
0
    def get_result(self, event=None):
        inp = self.entry.get()
        if self.mode == 'chat':
            if inp != '':
                self.entry.set('')
                self.output, self.input, attention_plot = evaluate(
                    inp, self.v, self.enc, self.dec, self.hparams['MAX_LEN'])
                self.attention_weights = attention_plot[:len(
                    self.output.split(' ')), :len(self.input.split(' '))]

                res = Vocabulary.restore_text(self.output)
                self.update_label(inp, res)
                self.display_text.config(state=tk.NORMAL)
                self.display_text.insert(
                    tk.END, self.text_history[-2] + self.text_history[-1])
                self.display_text.config(state=tk.DISABLED)
                self.display_text.see(tk.END)
        else:
            self.entry.set('')
            if self.auto_inp == None and inp != '':
                self.auto_inp = inp
                self.main_button.config(text='Next')

            self.output, self.input, attention_plot = evaluate(
                self.auto_inp, self.v, self.enc, self.dec,
                self.hparams['MAX_LEN'])
            self.attention_weights = attention_plot[:len(self.output.split(
                ' ')), :len(self.input.split(' '))]

            res = Vocabulary.restore_text(self.output)
            self.update_label(self.auto_inp, res)
            self.display_text.config(state=tk.NORMAL)
            self.display_text.insert(
                tk.END, self.text_history[-2] + self.text_history[-1])
            self.display_text.config(state=tk.DISABLED)
            self.display_text.see(tk.END)

            self.auto_inp = res