def submit(self):
        """Submit the text in the fields to gpt2 and launch a window displaying the generated articles."""
        try:
            number_of_samples = int(self.number_of_samples.get())  # Ensure the number of samples is an int
            assert number_of_samples > 0  # Ensure the number of samples is greater than 0
        except (ValueError, AssertionError):  # Display a dialog box to the user to notify them of the error
            messagebox.showerror('Invalid Value', 'Number of samples must be a positive number.')
            return

        try:
            words_per_sample = int(self.words_per_sample.get())  # Ensure the words per sample is an int
            # Ensure the words per sample is between 1 and 1023 (inclusive)
            assert (words_per_sample > 0) and (words_per_sample < 1024)
        except (ValueError, AssertionError):  # Display a dialog box to the user to notify them of the error
            messagebox.showerror('Invalid Value', 'Words per sample must be a whole number between 1 and 1023.')
            return

        title = self.title_text.get('1.0', tk.END).rstrip()  # Retrieve the text from the title field
        if len(title) == 0:  # Ensure text has be inputted in the title field
            messagebox.showerror('Invalid Title', 'Title must not be blank.')
            return

        # Retrieve the text from the initial content field
        initial_content = self.initial_content_text.get('1.0', tk.END).rstrip()

        # Generate samples based on the user input
        samples = Generator.get_instance().generate_as_tuple(title, initial_content, number_of_samples,
                                                             words_per_sample)

        # Display the generated samples
        sample_viewer = Gui.SampleViewer(samples)
        sample_viewer.start()
Exemple #2
0
        'no title for \'--title\' is specified.')
    return parser


def parse_arguments():
    """Create a parser and use it to parse the arguments given by Python, then return the parsed arguments."""
    parser = create_parser()
    parsed_args = parser.parse_args()
    return parsed_args


if __name__ == '__main__':
    args = parse_arguments()
    from generator import Generator

    gen = Generator.get_instance()

    if is_default_args(args):
        gen.launch_gui()
    elif not args.output_filename and not args.print:
        raise Exception(
            'Output has not been set to either console or an output file.\nUse the -h argument for help.'
        )
    elif args.output_filename and (args.output_filename in [
            args.filename, args.title_filename, args.content_filename
    ]):
        raise Exception(
            'Output filename cannot be the same as an input filename.\nUse the -h argument for help.'
        )
    elif args.filename:
        gen.generate_from_single_file(args.filename, args.num_samples,