From cb27a4ba8744d728104ca4852fd1d32c1721b767 Mon Sep 17 00:00:00 2001 From: Nick Walton Date: Tue, 9 Apr 2019 17:07:54 -0600 Subject: [PATCH] update --- .gitignore | 1 + AI-Adventure-1f64082e4e50.json | 12 ------------ main.py | 17 ++++++++--------- requirements.txt | 1 - static/script.js | 33 ++++++++++++++++++++++++++++----- templates/index.html | 1 + 6 files changed, 38 insertions(+), 27 deletions(-) delete mode 100644 AI-Adventure-1f64082e4e50.json diff --git a/.gitignore b/.gitignore index c28055a..ad0f679 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ gpt2/models/* .idea RL +*.json diff --git a/AI-Adventure-1f64082e4e50.json b/AI-Adventure-1f64082e4e50.json deleted file mode 100644 index 57101e9..0000000 --- a/AI-Adventure-1f64082e4e50.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "type": "service_account", - "project_id": "ai-adventure", - "private_key_id": "1f64082e4e50e81ef90de898a148cd8fc861b9c2", - "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDS3TlwjJln4tcw\nS+nngqPojTA2f48yhoXCGO9BuxblpZaxJ4wa7+YuQDKbEOsh5u8/0B3u1CSTC5bP\nWwpMrSXQZ3uMqNEw+nNdT5pdWdimuHZSqmIzUarsxZH2ta/1/uVuw5854ZvZI8UM\n8KliU+73q5gmssZ3QgwIuEfbpXUXtqYX6iG9Sk/o//ykeCS/r726DR8gY2p7OHsd\n6d0w2//rufd88rdCEVsITycErF9JnTXVc7yWKXCUyOLQwAfHiin/WZMzSO8kePwB\nLL6Zfi92NzhNbaCdB2VhBDhvtgtbm/GLN1gd1RRet0bJUe4q+7QGdUAEitDjfKeX\nlvzAcToNAgMBAAECggEALeIGcCef79uL0I4MORyTtvQV9B3glnFwJJKRaT+hFVpp\nRmYhFfFyqEi+2kAdsfRSxhNul/vgc4C3kaoxPQsGKemCmFJZpqswtDKwl7SHsIt9\n77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SWOEEHK564rYlCHWEZrThZWzGHHv1FOT\nA0qu+eWl21GfwU4irTEGCSU=\n-----END PRIVATE KEY-----\n", - "client_email": "360916456297-compute@developer.gserviceaccount.com", - "client_id": "102011190469340390254", - "auth_uri": "https://accounts.google.com/o/oauth2/auth", - "token_uri": "https://oauth2.googleapis.com/token", - "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/360916456297-compute%40developer.gserviceaccount.com" -} diff --git a/main.py b/main.py index 7eefa96..bc89509 100644 --- a/main.py +++ b/main.py @@ -17,7 +17,7 @@ import datetime from flask import g import os -os.environ['GOOGLE_APPLICATION_CREDENTIALS']="./AI-Adventure-1f64082e4e50.json" +os.environ['GOOGLE_APPLICATION_CREDENTIALS']="./AI-Adventure-2bb65e3a4e2f.json" from google.cloud import storage from google import cloud @@ -31,7 +31,8 @@ app = Flask(__name__) # App Info -gen_ip = "0.0.0.0:8090" +#gen_ip = "http://35.192.97.36:8010/" +gen_ip = "http://0.0.0.0:8090" 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 = {} @@ -91,9 +92,9 @@ def story_request(): if action_results is not None: response = action_results else: - - response = requests.post(gen_ip + "/generate", request.form) - response = response.json() + response = requests.post(gen_ip + "/generate", + data={"actions":"true","seed":seed, "prompt_num":prompt_num, "prompt": prompt, "choices": json.dumps(choices)}) + response = response.text cache_file(seed, prompt_num, choices, response, "choices") else: @@ -103,8 +104,8 @@ def story_request(): if result is not None: response = result else: - response = requests.post(gen_ip + "/generate", request.form) - response = response.json() + 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) @@ -119,8 +120,6 @@ def teardown_sess(_): if sess is not None: sess.close() - - if __name__ == '__main__': app.run(host='0.0.0.0', port=8080) diff --git a/requirements.txt b/requirements.txt index a1df4c0..c2e4d02 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -regex google-cloud-storage numpy flask diff --git a/static/script.js b/static/script.js index 1d0fef6..76269a0 100644 --- a/static/script.js +++ b/static/script.js @@ -1,16 +1,19 @@ -var 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"] +var prompts = ["You enter a dungeon with your trusty sword and shield. You are searching for the evil necromancer who killed your family and have heard that he resides at the bottom of the dungeon, guarded by legions of the undead. You enter the first door and see"] -start_text = "Adventurer@AIDungeon:~$ ./EnterDungeon \n
" +start_text = "Adventurer@AIDungeon:~$ ./EnterDungeon \n
" var acceptInput=false +var action_waiting = false var inputStr = "" +var typing = 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_min = 0 -var seed = Math.floor(Math.random() * (+seed_max - +seed_min)) + +seed_min; +//var seed = Math.floor(Math.random() * (+seed_max - +seed_min)) + +seed_min; +var seed = 108 console.log("Seed is ", seed) var StoryTracker = { @@ -41,8 +44,22 @@ var StoryTracker = { Typer.appendToText("\n\nOptions:") }, + actionWait:function(){ + console.log("action waiting ", action_waiting) + console.log("typing ", typing) + if(action_waiting == true || typing){ + setTimeout(StoryTracker.actionWait, 2000); + } + else{ + Typer.appendToText(" Generating...") + } + + }, + addNextAction:function(action_result){ + action_waiting = false + var action_results = JSON.parse(action_result) for (i = 0; i < 4; i++){ @@ -97,6 +114,8 @@ var StoryTracker = { StoryTracker.lastAction = StoryTracker.actions[choice_int] StoryTracker.lastStory = StoryTracker.results[choice_int] StoryTracker.makeActionRequests(StoryTracker.firstStory + StoryTracker.lastStory) + action_waiting = true + setTimeout(StoryTracker.actionWait, 2000); Typer.appendToText("\n") Typer.appendToText(StoryTracker.lastStory) Typer.appendToText("\n\nOptions:") @@ -128,7 +147,8 @@ var Typer={ }, appendToText:function(str){ - str = str.replace(".", "." + "") + str = str.replace(".", "." + "") + typing = true Typer.text = Typer.text + str; }, @@ -151,6 +171,9 @@ var Typer={ $("#console").html(text.replace(rtn,"
")) window.scrollBy(0,50) } + else{ + typing = false + } }, @@ -179,7 +202,7 @@ function writeAppend(str){ function startTyping(){ - addTextTimer = setInterval("typeWords()", 30) + addTextTimer = setInterval("typeWords()", 25) } diff --git a/templates/index.html b/templates/index.html index 7f41091..7ed2270 100644 --- a/templates/index.html +++ b/templates/index.html @@ -9,5 +9,6 @@
+ "\n\n\n\n"