This commit is contained in:
Nick Walton
2019-11-18 17:12:45 -07:00
parent 2edb9d46c2
commit 55c22f30e1
24 changed files with 27 additions and 17 deletions
View File
+21 -10
View File
@@ -1,11 +1,22 @@
from aidungeon.story.story_manager import *
from aidungeon.generator.gpt2.gpt2_generator import *
from aidungeon.story.story_manager import *
from story.story_manager import *
from generator.gpt2.gpt2_generator import *
CRED_FILE = "./AI-Adventure-2bb65e3a4e2f.json"
def console_print(text, width=75):
last_newline = 0
i = 0
while i < len(text):
if text[i] == "\n":
last_newline = 0
elif last_newline > width:
text = text[:i] + "\n" + text[i:]
else:
last_newline += 1
i += 1
def play_unconstrained():
generator = GPT2Generator()
prompt = get_story_start("knight")
@@ -14,8 +25,8 @@ def play_unconstrained():
story_manager.start_new_story(prompt, context=context)
print("\n")
print(context)
print(str(story_manager.story))
console_print(context)
console_print(str(story_manager.story))
while True:
action = input("> ")
@@ -26,14 +37,14 @@ def play_unconstrained():
action = "\n> " + action + "\n"
action = remove_profanity(action)
#action = first_to_second_person(action)
# action = first_to_second_person(action)
result = story_manager.act(action)
if player_died(result):
print(result + "\nGAME OVER")
console_print(result + "\nGAME OVER")
break
else:
print(result)
console_print(result)
if __name__ == '__main__':
@@ -1,9 +1,9 @@
from aidungeon.story.utils import *
from story.utils import *
import warnings
warnings.filterwarnings("ignore")
import os
import tensorflow as tf
from aidungeon.generator.gpt2.src import sample, encoder, model
from generator.gpt2.src import sample, encoder, model
import json
import numpy as np
@@ -18,7 +18,7 @@ class GPT2Generator:
self.top_p = top_p
self.model_name = "model_v1"
self.model_dir = "aidungeon/generator/gpt2/models"
self.model_dir = "generator/gpt2/models"
self.checkpoint_path = os.path.join(self.model_dir, self.model_name)
models_dir = os.path.expanduser(os.path.expandvars(self.model_dir))
@@ -1,6 +1,6 @@
import tensorflow as tf
from aidungeon.generator.gpt2.src import model
from generator.gpt2.src import model
def penalize_used(logits, output):
+1 -1
View File
@@ -5,6 +5,6 @@ if [ -d "$MODEL_DIRECTORY" ]; then
else
echo "Installing AIDungeon"
gsutil -m cp -r gs://aidungeon2model/model_v1 ./aidungeon/generator/gpt2/models
gsutil -m cp -r gs://aidungeon2model/model_v1 ./generator/gpt2/models
pip install -r requirements.txt
fi
@@ -1,5 +1,4 @@
from aidungeon.story.utils import *
from aidungeon.other.cacher import *
from story.utils import *
import json