This commit is contained in:
Nick Walton
2019-05-29 19:00:36 -06:00
10 changed files with 136 additions and 110 deletions
Binary file not shown.
Binary file not shown.
+5 -3
View File
@@ -1,6 +1,8 @@
#!/bin/bash
END=25
for ((I=0;I<END;I++));
START=80
END=100
for ((I=START;I<END;I++));
do
python3 main.py "$(($I * 4))" "$(( ($I + 1) * 4 ))" &
python3 main.py "$(($I * 1))" "$(( ($I + 1) * 1 ))" &
done
Binary file not shown.
Binary file not shown.
+21 -9
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
@@ -159,21 +160,24 @@ def story_request():
prompt_num = int(request.form["prompt_num"])
gen_actions = request.form["actions"]
if int(seed) < 0 or int(seed) > 1000:
if int(seed) < 0 or int(seed) > 100:
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:
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,7 +204,6 @@ def generate_cache():
start_seed = int(sys.argv[1])
end_seed = int(sys.argv[2])
# Generate story sections
prompt_num = 0
action_queue = []
@@ -210,10 +214,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 +227,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,15 +235,22 @@ def generate_cache():
response = action_results
else:
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]])
action_queue.append([seed, 0, new_choices, un_jsoned[j][1]])
if __name__ == '__main__':
if(len(sys.argv) > 1):
+60 -77
View File
@@ -1,20 +1,14 @@
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 = ""
var typing = false
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_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 +33,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 +66,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 +84,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,24 +150,28 @@ var StoryTracker = {
}
}
// Used to control the terminal like screen typing
var Typer={
text: null,
accessCountimer:null,
index:0,
speed:2,
startBlinker: function(){
accessCountimer=setInterval(function(){Typer.blinkCursor()},500)
},
content:function(){
return $("#console").html()
},
appendToText:function(str){
str = str.replace(".", "." + "<!-- laglag-->")
str = str.replace(".", "." + "<!-- laglaglag-->")
typing = true
Typer.text = Typer.text + str;
},
removeChar:function(){
var cont=Typer.content()
$("#console").html($("#console").html().substring(0,cont.length-1))
Typer.text = Typer.text.substring(0, Typer.text.length-1)
Typer.index = Typer.index - 1
},
addText:function(){
@@ -206,26 +196,6 @@ var Typer={
}
},
blinkCursor:function(){
if(should_blink == true){
if(blinkCounter > 10){
var cont=this.content()
if(cont.substring(cont.length-1,cont.length)=="|")
$("#console").html($("#console").html().substring(0,cont.length-1))
else
$("#console").append("|")
}
else{
blinkCounter += 1
}
}
}
}
@@ -236,8 +206,7 @@ function writeAppend(str){
function startTyping(){
addTextTimer = setInterval("typeWords()", 25)
addTextTimer = setInterval("typeWords()", 20)
}
@@ -245,6 +214,22 @@ function typeWords() {
Typer.addText()
}
document.addEventListener("keydown", KeyCheck);
function KeyCheck(evt) {
evt = evt || window.event
var charCode = evt.keyCode || evt.which
if(charCode == 8){
if(inputStr.length > 0){
console.log(inputStr)
inputStr = inputStr.substring(0, inputStr.length-1)
console.log(inputStr)
Typer.removeChar()
}
}
}
document.onkeypress = function(evt) {
if(acceptInput && !isMobileDevice()){
@@ -257,7 +242,6 @@ document.onkeypress = function(evt) {
StoryTracker.processInput(inputStr)
}
else{
var charStr = String.fromCharCode(charCode)
Typer.appendToText(charStr)
inputStr = inputStr + charStr
@@ -289,7 +273,6 @@ function start(){
StoryTracker.getFirstStory()
startTyping()
Typer.startBlinker()
console.log("Not mobile device");
document.getElementById('buttons').style.visibility='hidden';
+17 -17
View File
@@ -9,14 +9,15 @@ body {
width:80%;
margin-left:auto;
margin-right:auto;
margin-top:calc(30px + 4.0vh);;
margin-top:calc(30px + 4.0vh);
font-size:14px;
background-color: #000;
}
.about {
font-family: courier, monospace;
width:750px;
max-width: 800px;
width:80%;
margin-left:auto;
margin-right:auto;
margin-top:100px;
@@ -28,7 +29,7 @@ body {
}
.about h2{
color: #0bc;
font-size:20px;
font-size:16px;
}
a {
@@ -69,26 +70,26 @@ a {
#buttons {
position: relative;
bottom: 0px;
height: 60px;
width: 100%;
height: calc(100px + 12.0vw);
max-width: 800px;
width:80%;
color: 334;
background-color:#000;
text-align: center;
display: flex;
justify-content: space-between;
margin-left:auto;
margin-right:auto;
display: flex;
}
button {
border-color: #fff;
bottom: 40px;
color: #fff;
margin-top: 40px;
margin-left: 4%;
margin-right: 4%;
margin-bottom: 20px;
margin-top: 60px;
margin-left: 3.0vw;
margin-right: 3.0vw;
margin-bottom: 30px;
background-color: #111;
width: 18%;
height: 100px;
width: 14.0vw;
height: 12.0vw;
text-align: center;
border-radius: 25px;
font-size:30px;
@@ -118,8 +119,7 @@ button:focus{
text-align: center;
padding: 10px 5px;
text-decoration: none;
font-size:calc(14px + 0.5vh );
min-font-size:
font-size:18px;
}
/* Change the color of links on hover */
+19 -3
View File
@@ -1,10 +1,23 @@
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-139423787-1', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
<title>About</title>
<link rel="stylesheet" type="text/css" href="static/style.css">
</head>
<div class="topnav">
<a href="http://aidungeon.io">Home</a>
<a href="../">Home</a>
<a href="http://patreon.com/AIDungeon">Support</a>
</div>
<div class="about">
@@ -18,8 +31,11 @@
<br><br> As you can probably tell there's still a ways to go before AI will be your group's dungeon master, but even after running hundreds of adventures it still manages to surprise me in interesting ways. I've had a lot of fun making this and hope you enjoy it too.
<br><br><br> If you want to contact me about suggested improvements, comments, etc... feel free to email me about them. Nick Walton "nickwalton00@gmail.com". Also special thanks to Alan Walton and Max Robinson for their help and contributions.
<br><br> Warning: The GPT-2 model was trained on a huge amount of internet text so there might be offensive content.
<br><br> If you want to contact me about suggested improvements, comments, etc... feel free to email me about them at aidungeon.io@gmail.com.
<br><br> AI Dungeon was created by Nick Walton with the support of the <a href="https://pcc.cs.byu.edu/">BYU Percepton Cognition and Control Lab</a>, Alan Walton and Max Robinson.
</text>
</div>
+14 -1
View File
@@ -1,6 +1,18 @@
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-139423787-1', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
<title>Dungeon</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
@@ -10,7 +22,8 @@
</head>
<div class="topnav">
<a href="about.html">About</a>
<a href="http://patreon.com/AIDungeon">Support</a>
<a href="http://patreon.com/AIDungeon/overview">Support</a>
<a href=".">Restart</a>
</div>
<body>
<script type="text/javascript" src="static/script.js">