diff --git a/.gitignore b/.gitignore index 9661db6..a64a5ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -__pychache__/* -gpt2/__pycache__/* +**/__pychache__ gpt2/models/* -regex diff --git a/__pycache__/dungeon_master.cpython-37.pyc b/__pycache__/dungeon_master.cpython-37.pyc deleted file mode 100644 index 81fbde0..0000000 Binary files a/__pycache__/dungeon_master.cpython-37.pyc and /dev/null differ diff --git a/__pycache__/generator.cpython-35.pyc b/__pycache__/generator.cpython-35.pyc deleted file mode 100644 index 25cff22..0000000 Binary files a/__pycache__/generator.cpython-35.pyc and /dev/null differ diff --git a/__pycache__/generator.cpython-36.pyc b/__pycache__/generator.cpython-36.pyc deleted file mode 100644 index 4d391c2..0000000 Binary files a/__pycache__/generator.cpython-36.pyc and /dev/null differ diff --git a/__pycache__/generator.cpython-37.pyc b/__pycache__/generator.cpython-37.pyc index ae333f0..a2c23a6 100644 Binary files a/__pycache__/generator.cpython-37.pyc and b/__pycache__/generator.cpython-37.pyc differ diff --git a/__pycache__/main.cpython-37.pyc b/__pycache__/main.cpython-37.pyc deleted file mode 100644 index 4021a17..0000000 Binary files a/__pycache__/main.cpython-37.pyc and /dev/null differ diff --git a/__pycache__/utils.cpython-35.pyc b/__pycache__/utils.cpython-35.pyc deleted file mode 100644 index 4ea50b0..0000000 Binary files a/__pycache__/utils.cpython-35.pyc and /dev/null differ diff --git a/__pycache__/utils.cpython-36.pyc b/__pycache__/utils.cpython-36.pyc deleted file mode 100644 index f78249e..0000000 Binary files a/__pycache__/utils.cpython-36.pyc and /dev/null differ diff --git a/__pycache__/utils.cpython-37.pyc b/__pycache__/utils.cpython-37.pyc index 66d02d0..149ae0a 100644 Binary files a/__pycache__/utils.cpython-37.pyc and b/__pycache__/utils.cpython-37.pyc differ diff --git a/generator.py b/generator.py index a2cade4..0e6d80d 100644 --- a/generator.py +++ b/generator.py @@ -13,7 +13,7 @@ pos_action_starts = ["You attack", "You tell", "You use", "You go"] class StoryGenerator(): - def __init__(self, sess, length=80, temperature=0.9, top_k=40): + def __init__(self, sess, length=75, temperature=0.9, top_k=40): seed = None batch_size=1 diff --git a/generator.pyc b/generator.pyc deleted file mode 100644 index de4f2cd..0000000 Binary files a/generator.pyc and /dev/null differ diff --git a/gpt2/__init__.pyc b/gpt2/__init__.pyc deleted file mode 100644 index cc3c924..0000000 Binary files a/gpt2/__init__.pyc and /dev/null differ diff --git a/gpt2/__pycache__/__init__.cpython-37.pyc b/gpt2/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..b59cf9e Binary files /dev/null and b/gpt2/__pycache__/__init__.cpython-37.pyc differ diff --git a/gpt2/src/__init__.py b/gpt2/src/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/gpt2/src/__init__.pyc b/gpt2/src/__init__.pyc deleted file mode 100644 index de96e09..0000000 Binary files a/gpt2/src/__init__.pyc and /dev/null differ diff --git a/gpt2/src/__pycache__/__init__.cpython-35.pyc b/gpt2/src/__pycache__/__init__.cpython-35.pyc deleted file mode 100644 index 2c7cfad..0000000 Binary files a/gpt2/src/__pycache__/__init__.cpython-35.pyc and /dev/null differ diff --git a/gpt2/src/__pycache__/__init__.cpython-36.pyc b/gpt2/src/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 2a9af0a..0000000 Binary files a/gpt2/src/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/gpt2/src/__pycache__/__init__.cpython-37.pyc b/gpt2/src/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 11790e4..0000000 Binary files a/gpt2/src/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/gpt2/src/__pycache__/encoder.cpython-35.pyc b/gpt2/src/__pycache__/encoder.cpython-35.pyc deleted file mode 100644 index 129e22e..0000000 Binary files a/gpt2/src/__pycache__/encoder.cpython-35.pyc and /dev/null differ diff --git a/gpt2/src/__pycache__/encoder.cpython-36.pyc b/gpt2/src/__pycache__/encoder.cpython-36.pyc deleted file mode 100644 index 54dee2d..0000000 Binary files a/gpt2/src/__pycache__/encoder.cpython-36.pyc and /dev/null differ diff --git a/gpt2/src/__pycache__/encoder.cpython-37.pyc b/gpt2/src/__pycache__/encoder.cpython-37.pyc index ee9bc1c..c23a36b 100644 Binary files a/gpt2/src/__pycache__/encoder.cpython-37.pyc and b/gpt2/src/__pycache__/encoder.cpython-37.pyc differ diff --git a/gpt2/src/__pycache__/model.cpython-35.pyc b/gpt2/src/__pycache__/model.cpython-35.pyc deleted file mode 100644 index 93e0087..0000000 Binary files a/gpt2/src/__pycache__/model.cpython-35.pyc and /dev/null differ diff --git a/gpt2/src/__pycache__/model.cpython-36.pyc b/gpt2/src/__pycache__/model.cpython-36.pyc deleted file mode 100644 index 800652b..0000000 Binary files a/gpt2/src/__pycache__/model.cpython-36.pyc and /dev/null differ diff --git a/gpt2/src/__pycache__/model.cpython-37.pyc b/gpt2/src/__pycache__/model.cpython-37.pyc index 031ba0b..65b91cf 100644 Binary files a/gpt2/src/__pycache__/model.cpython-37.pyc and b/gpt2/src/__pycache__/model.cpython-37.pyc differ diff --git a/gpt2/src/__pycache__/sample.cpython-35.pyc b/gpt2/src/__pycache__/sample.cpython-35.pyc deleted file mode 100644 index 4f76902..0000000 Binary files a/gpt2/src/__pycache__/sample.cpython-35.pyc and /dev/null differ diff --git a/gpt2/src/__pycache__/sample.cpython-36.pyc b/gpt2/src/__pycache__/sample.cpython-36.pyc deleted file mode 100644 index 7eed82a..0000000 Binary files a/gpt2/src/__pycache__/sample.cpython-36.pyc and /dev/null differ diff --git a/gpt2/src/__pycache__/sample.cpython-37.pyc b/gpt2/src/__pycache__/sample.cpython-37.pyc index 6c4cd29..d243bb1 100644 Binary files a/gpt2/src/__pycache__/sample.cpython-37.pyc and b/gpt2/src/__pycache__/sample.cpython-37.pyc differ diff --git a/main.py b/main.py index 9419a37..c4472fc 100644 --- a/main.py +++ b/main.py @@ -30,6 +30,8 @@ from flask import Flask, render_template, request app = Flask(__name__) +phrases = [" You attack", " You use", " You tell", " You use"] + session = None generator = None @@ -44,16 +46,15 @@ def root(): def story_request(): print("****Generating Story****") prompt = request.form["prompt"] # given prompt - phrase = request.form["phrase"] gen_actions = request.form["actions"] # given prompt - print("\n Given prompt is: \n",prompt," ", phrase,"\n") + print("\n Given prompt is: \n",prompt," ","\n") generator = get_generator() if gen_actions == "true": - action, result = generator.generate_action_result(prompt, phrase) - response = json.dumps([action, result]) + action_results = [generator.generate_action_result(prompt, phrase) for phrase in phrases] + response = json.dumps(action_results) else: response = generator.generate_story_block(prompt) diff --git a/static/script.js b/static/script.js index 182da21..356af10 100644 --- a/static/script.js +++ b/static/script.js @@ -20,7 +20,7 @@ var StoryTracker = { getFirstStory:function(){ console.log("Requesting first story") Typer.appendToText(initial_prompt) - StoryTracker.requestStory(initial_prompt, "None") + StoryTracker.requestStory(initial_prompt) }, @@ -36,26 +36,33 @@ var StoryTracker = { }, addNextAction:function(action_result){ - var action_result = JSON.parse(action_result) - action = action_result[0] - result = action_result[1] - - - StoryTracker.actions.push(action) - StoryTracker.results.push(result) - var print_action = "\n" + String(StoryTracker.action_int) + ") " + action - StoryTracker.action_int += 1 - Typer.appendToText(print_action) + + var action_results = JSON.parse(action_result) + + for (i = 0; i < 4; i++){ + + action_result = action_results[i] - if (StoryTracker.action_int > 3){ - Typer.appendToText("\nWhich action do you choose? ") - StoryTracker.action_int = 0 - acceptInput = true + action = action_result[0] + result = action_result[1] - if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) { - setTimeout(StoryTracker.mobileButton, 1000); + + StoryTracker.actions.push(action) + StoryTracker.results.push(result) + var print_action = "\n" + String(StoryTracker.action_int) + ") " + action + StoryTracker.action_int += 1 + Typer.appendToText(print_action) + + if (StoryTracker.action_int > 3){ + Typer.appendToText("\nWhich action do you choose? ") + StoryTracker.action_int = 0 + acceptInput = true + + if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) { + setTimeout(StoryTracker.mobileButton, 1000); + } + } - } }, @@ -76,19 +83,18 @@ var StoryTracker = { StoryTracker.actions = [] StoryTracker.results = [] - for (i = 0; i < 4; i++){ - StoryTracker.requestAction(prompt, action_list[i]) - } + StoryTracker.requestAction(prompt) + }, - requestStory:function(prompt, phrase){ - $.post("/generate", {actions: false, prompt, phrase}, + requestStory:function(prompt){ + $.post("/generate", {actions: false, prompt}, StoryTracker.addNextStory) }, - requestAction:function(prompt, phrase){ - $.post("/generate", {actions: true, prompt, phrase}, + requestAction:function(prompt){ + $.post("/generate", {actions: true, prompt}, StoryTracker.addNextAction) }, @@ -101,7 +107,7 @@ var StoryTracker = { StoryTracker.lastAction = StoryTracker.actions[choice_int] StoryTracker.lastStory = StoryTracker.results[choice_int] StoryTracker.makeActionRequests(StoryTracker.firstStory + StoryTracker.lastStory) - Typer.appendToText("\n\n") + Typer.appendToText("\n") Typer.appendToText(StoryTracker.lastStory) Typer.appendToText("\n\nOptions:") } @@ -187,7 +193,7 @@ function writeAppend(str){ function startTyping(){ - addTextTimer = setInterval("typeWords()", 40) + addTextTimer = setInterval("typeWords()", 50) }