From 7dbc3181a402efa9cfbb7f68cd86c10c15e3ac4a Mon Sep 17 00:00:00 2001 From: Nick Walton Date: Mon, 18 Nov 2019 17:50:50 -0700 Subject: [PATCH] fixed bug --- console_play.py | 10 ++++------ generator/gpt2/gpt2_generator.py | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/console_play.py b/console_play.py index c305d29..37eccf0 100644 --- a/console_play.py +++ b/console_play.py @@ -9,11 +9,13 @@ def console_print(text, width=75): while i < len(text): if text[i] == "\n": last_newline = 0 - elif last_newline > width: + elif last_newline > width and text[i] == " ": text = text[:i] + "\n" + text[i:] + last_newline = 0 else: last_newline += 1 i += 1 + print(text) def play_unconstrained(): @@ -22,10 +24,7 @@ def play_unconstrained(): generator = GPT2Generator() prompt = get_story_start("knight") context = get_context("knight") - print("DEUBUG: Context is ", context) - print("DEBUG: Prompt is ", prompt) story_manager = UnconstrainedStoryManager(generator) - print("Generating initial story.") story_manager.start_new_story(prompt, context=context) with open('opening.txt', 'r') as file: @@ -34,8 +33,7 @@ def play_unconstrained(): print(starter) print("\n") - console_print(context) - console_print(str(story_manager.story)) + console_print(context + str(story_manager.story)) while True: action = input("> ") diff --git a/generator/gpt2/gpt2_generator.py b/generator/gpt2/gpt2_generator.py index fe97679..13456d4 100644 --- a/generator/gpt2/gpt2_generator.py +++ b/generator/gpt2/gpt2_generator.py @@ -72,6 +72,7 @@ class GPT2Generator: result = result.replace('."', '".') result = result.replace("#", "") result = result.replace("*", "") + result = result.replace("\n\n", "\n") #result = first_to_second_person(result) result = remove_profanity(result) @@ -86,7 +87,7 @@ class GPT2Generator: def generate(self, prompt, options=None, seed=1): - debug_print = True + debug_print = False prefix = self.prompt_replace(prompt) if debug_print: