From 873fe433621f5336edaaa6f6d25a709c26c52366 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 10 Apr 2019 20:23:20 -0600 Subject: [PATCH 1/8] button fix --- static/script.js | 33 ++++++++++++++++++++++++--------- static/style.css | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/static/script.js b/static/script.js index 5152471..fe74cb7 100644 --- a/static/script.js +++ b/static/script.js @@ -23,6 +23,16 @@ function isMobileDevice() { return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) }; + +function buttonCheck(){ + if(typing == true){ + setTimeout(buttonCheck, 500); + } + else{ + document.getElementById('buttons').style.visibility='visible'; + } +} + var StoryTracker = { firstStory: null, lastStory: null, @@ -84,6 +94,10 @@ var StoryTracker = { Typer.appendToText("\nWhich action do you choose? ") StoryTracker.action_int = 0 acceptInput = true + + if(isMobileDevice()){ + setTimeout(buttonCheck, 500); + } } } @@ -130,6 +144,11 @@ var StoryTracker = { Typer.appendToText("\nWhich action do you choose? ") acceptInput = true + + if(isMobileDevice()){ + setTimeout(buttonCheck, 500); + } + } @@ -243,6 +262,8 @@ document.onkeypress = function(evt) { function onButtonClick(num){ + document.getElementById('buttons').style.visibility='hidden'; + if (acceptInput == true){ acceptInput = false num = String(num) @@ -263,15 +284,9 @@ function start(){ startTyping() Typer.startBlinker() - - if(isMobileDevice()){ - console.log("Mobile device"); - } - else{ - console.log("Not mobile device"); - document.getElementById('buttons').style.visibility='hidden'; - } - + + console.log("Not mobile device"); + document.getElementById('buttons').style.visibility='hidden'; } diff --git a/static/style.css b/static/style.css index bf00844..33b212b 100644 --- a/static/style.css +++ b/static/style.css @@ -67,7 +67,7 @@ a { } #buttons { - position: absolute; + position: relative; bottom: 80px; height: 60px; width: 100%; From 1db8a6eb4ba73127afd68cc4656d8f803b4e4ce2 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 10 Apr 2019 20:31:06 -0600 Subject: [PATCH 2/8] bottom change --- static/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/style.css b/static/style.css index 33b212b..8510d9c 100644 --- a/static/style.css +++ b/static/style.css @@ -68,7 +68,7 @@ a { #buttons { position: relative; - bottom: 80px; + bottom: 0px; height: 60px; width: 100%; color: 334; From 7cadc6e2e79035d2ca33bbf2311c9059023d1e19 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 10 Apr 2019 20:44:44 -0600 Subject: [PATCH 3/8] fix mobile button --- static/script.js | 4 ++-- static/style.css | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/static/script.js b/static/script.js index fe74cb7..bdb7ec9 100644 --- a/static/script.js +++ b/static/script.js @@ -63,7 +63,7 @@ var StoryTracker = { actionWait:function(){ if(action_waiting == true || typing){ - setTimeout(StoryTracker.actionWait, 2000); + setTimeout(StoryTracker.actionWait, 4000); } else{ Typer.appendToText(" Generating...") @@ -133,7 +133,7 @@ var StoryTracker = { StoryTracker.lastStory = StoryTracker.results[choice_int] StoryTracker.makeActionRequests(StoryTracker.firstStory + StoryTracker.lastStory) action_waiting = true - setTimeout(StoryTracker.actionWait, 2000); + setTimeout(StoryTracker.actionWait, 4000); Typer.appendToText("\n") Typer.appendToText(StoryTracker.lastStory) Typer.appendToText("\n\nOptions:") diff --git a/static/style.css b/static/style.css index 8510d9c..dda4f40 100644 --- a/static/style.css +++ b/static/style.css @@ -79,11 +79,13 @@ a { } button { - border-color: #000 + border-color: #fff; bottom: 40px; color: #fff; + margin-top: 40px; margin-left: 4%; margin-right: 4%; + margin-bottom: 20px; background-color: #111; width: 18%; height: 100px; @@ -93,6 +95,11 @@ button { } +button:focus{ + background-color: #0bc; +} + + /* Add a black background color to the top navigation */ .topnav { background-color: #000; From 14565a8ccc0c3851a57b40cdeaf293d369ac3862 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 10 Apr 2019 21:00:33 -0600 Subject: [PATCH 4/8] sizing change --- static/style.css | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/static/style.css b/static/style.css index dda4f40..4090bb1 100644 --- a/static/style.css +++ b/static/style.css @@ -9,7 +9,7 @@ body { width:80%; margin-left:auto; margin-right:auto; - margin-top:100px; + margin-top:calc(30px + 4.0vh); font-size:14px; background-color: #000; } @@ -103,7 +103,6 @@ button:focus{ /* Add a black background color to the top navigation */ .topnav { background-color: #000; - overflow: hidden; max-width: 800px; width:80%; margin-left:auto; @@ -113,13 +112,14 @@ button:focus{ /* Style the links inside the navigation bar */ .topnav a { - font-family: courier, monospace; + font-family: courier, monospace; display: inline-block; color: #0bc; text-align: center; padding: 10px 5px; text-decoration: none; - font-size: 16px; + font-size:calc(2.0vh + 0.5vw); + min-font-size: } /* Change the color of links on hover */ From bb5c5a650c060bd4b816302419db4e2894de13f9 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 10 Apr 2019 21:06:07 -0600 Subject: [PATCH 5/8] adjusted font slightly --- static/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/style.css b/static/style.css index 4090bb1..308558c 100644 --- a/static/style.css +++ b/static/style.css @@ -118,7 +118,7 @@ button:focus{ text-align: center; padding: 10px 5px; text-decoration: none; - font-size:calc(2.0vh + 0.5vw); + font-size:calc(12px + 1.0vh ); min-font-size: } From fb4ab85fc4ab569ab094cf74c06928eeaf5232cc Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 10 Apr 2019 21:10:43 -0600 Subject: [PATCH 6/8] more changes --- static/script.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/static/script.js b/static/script.js index bdb7ec9..9bc374f 100644 --- a/static/script.js +++ b/static/script.js @@ -13,7 +13,7 @@ var should_blink = false var blinkCounter = 0 var action_list = ["You attack", "You tell", "You use", "You go"] var prompt_num = 0 -var seed_max = 100 +var seed_max = 1000 var seed_min = 0 var seed = Math.floor(Math.random() * (+seed_max - +seed_min)) + +seed_min; //var seed = 108 @@ -193,7 +193,6 @@ var Typer={ var rtn= new RegExp("\n", "g") $("#console").html(text.replace(rtn,"
")) - window.scrollBy(0,50) } else{ typing = false @@ -241,7 +240,7 @@ function typeWords() { document.onkeypress = function(evt) { - if(acceptInput){ + if(acceptInput && !isMobileDevice()){ evt = evt || window.event var charCode = evt.keyCode || evt.which From fd08bf54ccdf987ebe7c3945f13ca46db35362ab Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 10 Apr 2019 21:34:46 -0600 Subject: [PATCH 7/8] more various changes --- main.py | 3 +-- static/script.js | 13 ++++++++----- templates/about.html | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 2646317..12038ac 100644 --- a/main.py +++ b/main.py @@ -31,8 +31,7 @@ app = Flask(__name__) # App Info -#gen_ip = "http://35.192.97.36:8010/" -gen_ip = "http://0.0.0.0:8090" +gen_ip = "http://35.192.97.36:8010" phrases = [" You attack", " You use", " You tell", " You go"] prompts = ["You enter a dungeon with your trusty sword and shield. You are searching for the evil necromancer who killed your family. You've heard that he resides at the bottom of the dungeon, guarded by legions of the undead. You enter the first door and see"] requested_map = {} diff --git a/static/script.js b/static/script.js index 9bc374f..41f7ea8 100644 --- a/static/script.js +++ b/static/script.js @@ -62,11 +62,14 @@ var StoryTracker = { }, actionWait:function(){ - if(action_waiting == true || typing){ - setTimeout(StoryTracker.actionWait, 4000); - } - else{ - Typer.appendToText(" Generating...") + + if(action_waiting == true){ + if(typing == true || acceptInput == true){ + setTimeout(StoryTracker.actionWait, 5000); + } + else{ + Typer.appendToText(" Generating...") + } } }, diff --git a/templates/about.html b/templates/about.html index 087853d..9ba5a66 100644 --- a/templates/about.html +++ b/templates/about.html @@ -10,7 +10,7 @@

About AI Dungeon

- AIDungeon is an AI generated text adventure that uses deep learning to create each adventure. It uses OpenAI's new GPT-2 model, which has 117 million parameters, to generate each story block and possible action. + AI Dungeon is an AI generated text adventure that uses deep learning to create each adventure. It uses OpenAI's new GPT-2 model, which has 117 million parameters, to generate each story block and possible action.

The first couple sentences of AIDungeon and the action verbs are handcrafted, but everything else is not. Each time an option is chosen, the initial prompt, the last story block, and the last action are fed into the neural network. The resulting story and action options are then output by the model. From 18ed0538d0bdd83a88d845862f531f87a21ff7a6 Mon Sep 17 00:00:00 2001 From: Max Robinson Date: Thu, 11 Apr 2019 18:14:23 -0600 Subject: [PATCH 8/8] Added defense against invalid seeds --- main.py | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/main.py b/main.py index 12038ac..f97817e 100644 --- a/main.py +++ b/main.py @@ -22,7 +22,7 @@ os.environ['GOOGLE_APPLICATION_CREDENTIALS']="./AI-Adventure-2bb65e3a4e2f.json" from google.cloud import storage from google import cloud import json -from flask import Flask, render_template, request +from flask import Flask, render_template, request, abort storage_client = storage.Client() bucket = storage_client.get_bucket("dungeon-cache") from flask import Response @@ -39,61 +39,65 @@ requested_map = {} @app.route('/') def root(): return render_template('index.html') - + @app.route('/index.html') def index(): return render_template('index.html') - + @app.route('/about.html') def about(): return render_template('about.html') - - + + def cache_file(seed, prompt_num, choices, response, tag): blob_file_name = "p" + str(prompt_num) + "/seed" + str(seed) + "/" + tag for action in choices: blob_file_name = blob_file_name + str(action) blob = bucket.blob(blob_file_name) - + blob.upload_from_string(response) - + print("File ", blob_file_name, " cached") def retrieve_from_cache(seed, prompt_num, choices, tag): blob_file_name = "p" + str(prompt_num) + "/seed" + str(seed) + "/" + tag - + for action in choices: blob_file_name = blob_file_name + str(action) - + blob = bucket.blob(blob_file_name) - + if blob.exists(storage_client): result = blob.download_as_string().decode("utf-8") print(blob_file_name, " found in cache") else: result = None print(blob_file_name, " not found in cache") - + return result - + @app.route('/generate', methods=['POST']) def story_request(): print("****Generating Story****") seed = request.form["seed"] prompt_num = int(request.form["prompt_num"]) - gen_actions = request.form["actions"] - + gen_actions = request.form["actions"] + + if int(seed) < 0 or int(seed) > 1000: + print("Invalid seed: " + seed) + abort(404) + if gen_actions == "true": - prompt = request.form["prompt"] + prompt = request.form["prompt"] choices = json.loads(request.form["choices"]) print("Getting response for seed ", seed, " prompt_num ", prompt_num, " and choices ", choices) - + action_results = retrieve_from_cache(seed, prompt_num, choices, "choices") - + if action_results is not None: response = action_results else: @@ -102,32 +106,32 @@ def story_request(): response = response.text cache_file(seed, prompt_num, choices, response, "choices") else: - + print("Getting response for seed ", seed, " prompt_num ", prompt_num) result = retrieve_from_cache(seed, prompt_num, [], "story") - + if result is not None: response = result else: response = requests.post(gen_ip + "/generate", data={"actions":"false","seed":seed, "prompt_num":prompt_num}) response=response.text cache_file(seed, prompt_num, [], response, "story") - + print("\nGenerated response is: \n", response) print("") - + return response - + @app.teardown_appcontext def teardown_sess(_): sess = g.pop("sess",None) - + if sess is not None: sess.close() if __name__ == '__main__': app.run(host='0.0.0.0', port=8080) - - - + + + # [START gae_python37_render_template]