This commit is contained in:
Nick Walton
2019-04-12 18:44:09 -06:00
parent 9869f4379b
commit 90fd0d1b6a
3 changed files with 61 additions and 60 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
#!/bin/bash
START=0
END=15
END=25
for ((I=START;I<END;I++));
do
python3 main.py "$(($I * 1))" "$(( ($I + 1) * 1 ))" &
python3 main.py "$(($I * 2))" "$(( ($I + 1) * 2 ))" &
done
+23 -10
View File
@@ -32,6 +32,7 @@ import gpt2.src.encoder as encoder
# App Info
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"]
continuing_prompts = ["You are in a dungeon with your sword and shield. You are on a quest to defeat the necromancer. This dungeon is full of zombie and skeletons."]
app = Flask(__name__)
# Encoder Info
@@ -124,7 +125,7 @@ def about():
def cache_file(seed, prompt_num, choices, response, tag):
blob_file_name = "fixed-prompt" + str(prompt_num) + "/seed" + str(seed) + "/" + tag
blob_file_name = "prompt" + 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)
@@ -135,7 +136,7 @@ def cache_file(seed, prompt_num, choices, response, tag):
def retrieve_from_cache(seed, prompt_num, choices, tag):
blob_file_name = "fixed-prompt" + str(prompt_num) + "/seed" + str(seed) + "/" + tag
blob_file_name = "prompt" + str(prompt_num) + "/seed" + str(seed) + "/" + tag
for action in choices:
blob_file_name = blob_file_name + str(action)
@@ -165,15 +166,18 @@ def story_request():
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:
last_action_result = request.form["last_action_result"]
prompt = continuing_prompts[prompt_num] + last_action_result
print("\n\nAction prompt is \n ", prompt)
action_results = [generate_action_result(prompt, phrase) for phrase in phrases]
response = json.dumps(action_results)
cache_file(seed, prompt_num, choices, response, "choices")
@@ -185,7 +189,8 @@ def story_request():
if result is not None:
response = result
else:
response = generate_story_block(prompts[prompt_num])
prompt = prompts[prompt_num]
response = generate_story_block(prompt)
cache_file(seed, prompt_num, [], response, "story")
print("\nGenerated response is: \n", response)
@@ -199,6 +204,7 @@ def generate_cache():
start_seed = int(sys.argv[1])
end_seed = int(sys.argv[2])
if len(sys.argv)
# Generate story sections
prompt_num = 0
@@ -210,10 +216,12 @@ def generate_cache():
response = result
else:
prompt = prompts[prompt_num]
#print("\n Story prompt is ", prompt)
response = generate_story_block(prompt)
#print("\n Story response is ", response)
cache_file(seed, prompt_num, [], response, "story")
action_queue.append([seed,0,[],prompt+response, ""])
action_queue.append([seed,0,[],response])
while(True):
@@ -221,8 +229,7 @@ def generate_cache():
seed = next_gen[0]
prompt_num = next_gen[1]
choices = next_gen[2]
initial_prompt = next_gen[3]
last_action_result = next_gen[4]
last_action_result = next_gen[3]
action_results = retrieve_from_cache(seed, prompt_num, choices, "choices")
@@ -230,16 +237,22 @@ def generate_cache():
response = action_results
else:
prompt = initial_prompt + last_action_result
if len(choices) is 0:
prompt = prompts[prompt_num] + last_action_result
else:
prompt = continuing_prompts[prompt_num] + last_action_result
#print("\n\n Action prompt is \n ", prompt)
action_results = [generate_action_result(prompt, phrase) for phrase in phrases]
response = json.dumps(action_results)
#print("\n\n Action
cache_file(seed, prompt_num, choices, response, "choices")
un_jsoned = json.loads(response)
for j in range(4):
new_choices = choices[:]
new_choices.append(j)
action_queue.append([seed, 0, new_choices, initial_prompt, un_jsoned[j][1]])
action_queue.append([seed, 0, new_choices, un_jsoned[j][1]])
if __name__ == '__main__':
if(len(sys.argv) > 1):
+36 -48
View File
@@ -1,10 +1,5 @@
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 = "<span id='a'>Adventurer@AIDungeon</span>:<span id='b'>~</span><span id='c'>$</span> ./EnterDungeon \n <br/><!-- laglaglaglaglaglaglaglaglaglaglag-->"
input_form = '<form><input type="text" choice="your_choice"></form>'
var acceptInput=false
var action_waiting = false
var inputStr = ""
@@ -15,6 +10,7 @@ var action_list = ["You attack", "You tell", "You use", "You go"]
var prompt_num = 0
var seed_max = 100
var seed_min = 0;
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"]
if(seed == -1){
var seed = Math.floor(Math.random() * (+seed_max - +seed_min)) + +seed_min;
@@ -39,34 +35,26 @@ function buttonCheck(){
}
var StoryTracker = {
firstStory: null,
lastStory: null,
lastAction: null,
lastActionResult: "",
actions: [],
results: [],
choices: [],
action_int: 0,
startPrompt: prompts[prompt_num],
// Requests the first story
getFirstStory:function(){
console.log("Requesting first story")
Typer.appendToText(StoryTracker.startPrompt)
StoryTracker.requestFirstStory(StoryTracker.startPrompt)
Typer.appendToText(prompts[prompt_num])
StoryTracker.requestFirstStory()
},
addNextStory:function(story){
StoryTracker.lastStory = story
if (StoryTracker.firstStory == null){
StoryTracker.firstStory = StoryTracker.startPrompt + story
}
StoryTracker.makeActionRequests(StoryTracker.firstStory + StoryTracker.lastStory)
addFirstStory:function(story){
StoryTracker.lastActionResult = story
StoryTracker.makeActionRequests()
Typer.appendToText(story)
action_waiting = true
setTimeout(StoryTracker.actionWait, 10000);
},
// Called after requesting options, prints generating msg if waits too lng
actionWait:function(){
if(action_waiting == true){
@@ -80,12 +68,17 @@ var StoryTracker = {
},
// Callback for action request
addNextAction:function(action_result){
action_waiting = false
// Response receieved no longer waiting
var action_results = JSON.parse(action_result)
Typer.appendToText("\n\nOptions:")
action_waiting = false
StoryTracker.actions = []
StoryTracker.results = []
for (i = 0; i < 4; i++){
action_result = action_results[i]
@@ -93,57 +86,52 @@ var StoryTracker = {
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
var print_action = "\n" + String(i) + ") " + action
Typer.appendToText(print_action)
if (StoryTracker.action_int > 3){
if (i == 3){
Typer.appendToText("\nWhich action do you choose? ")
StoryTracker.action_int = 0
// Now we wait for the user to give input to us.
acceptInput = true
if(isMobileDevice()){
setTimeout(buttonCheck, 500);
}
}
}
}
},
makeActionRequests:function(prompt){
StoryTracker.actions = []
StoryTracker.results = []
StoryTracker.requestActions(prompt, JSON.stringify(StoryTracker.choices))
// Make a request to the server for result actions
makeActionRequests:function(){
action_waiting = true
setTimeout(StoryTracker.actionWait, 10000);
StoryTracker.requestActions(StoryTracker.lastActionResult, JSON.stringify(StoryTracker.choices))
},
requestFirstStory:function(prompt){
requestFirstStory:function(){
$.post("/generate", {actions: false, seed, prompt_num},
StoryTracker.addNextStory)
StoryTracker.addFirstStory)
},
requestActions:function(prompt, choices){
$.post("/generate", {actions: true, seed, prompt_num, prompt, choices},
requestActions:function(last_action_result, choices){
$.post("/generate", {actions: true, seed, prompt_num, last_action_result, choices},
StoryTracker.addNextAction)
},
// Called once a choice has been made by button or entering.
processInput:function(){
var choice_int = parseInt(inputStr, 10)
if(choice_int >= 0 && choice_int <= 3){
console.log("choice_int is %d", choice_int)
StoryTracker.choices.push(choice_int)
StoryTracker.lastAction = StoryTracker.actions[choice_int]
StoryTracker.lastStory = StoryTracker.results[choice_int]
StoryTracker.lastActionResult = StoryTracker.results[choice_int]
StoryTracker.makeActionRequests(StoryTracker.firstStory + StoryTracker.lastStory)
action_waiting = true
setTimeout(StoryTracker.actionWait, 10000);
Typer.appendToText("\n")
Typer.appendToText(StoryTracker.lastStory)
Typer.appendToText(StoryTracker.lastActionResult)
}
else{
@@ -164,13 +152,14 @@ var StoryTracker = {
}
}
// Used to control the terminal like screen typing
var Typer={
text: null,
accessCountimer:null,
accessBlinktimer:null,
index:0,
speed:2,
startBlinker: function(){
accessCountimer=setInterval(function(){Typer.blinkCursor()},500)
accessBlinktimer=setInterval(function(){Typer.blinkCursor()},500)
},
content:function(){
@@ -237,7 +226,6 @@ function writeAppend(str){
function startTyping(){
addTextTimer = setInterval("typeWords()", 25)
}