mirror of
https://github.com/wassname/Clover-Edition.git
synced 2026-09-11 11:51:53 +08:00
added_json
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
**/__pychache__
|
||||
.idea
|
||||
*.json
|
||||
AI-Adventure-2bb65e3a4e2f.json
|
||||
*.pyc
|
||||
*.pyo
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"n_vocab": 50257,
|
||||
"n_ctx": 1024,
|
||||
"n_embd": 768,
|
||||
"n_head": 12,
|
||||
"n_layer": 12
|
||||
}
|
||||
@@ -7,40 +7,60 @@ from flask import Flask, render_template, request, abort
|
||||
from story.story_manager import *
|
||||
from generator.web.web_generator import *
|
||||
from other.cacher import *
|
||||
import numpy as np
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = '#d\xe0\xd1\xfb\xee\xa4\xbb\xd0\xf0/e)\xb5g\xdd<`\xc7\xa5\xb0-\xb8d0S'
|
||||
GOOGLE_CRED_LOCATION = "./AI-Adventure-2bb65e3a4e2f.json"
|
||||
CRED_FILE = "./AI-Adventure-2bb65e3a4e2f.json"
|
||||
|
||||
|
||||
# Initializes everything for a session
|
||||
def story_init(session, seed):
|
||||
pass
|
||||
|
||||
# Routes to index
|
||||
@app.route('/')
|
||||
def root():
|
||||
seed = -1
|
||||
data = {'seed': seed}
|
||||
return render_template('index.html', data=data)
|
||||
|
||||
# Starts an adventure
|
||||
@app.route('/index.html')
|
||||
def index():
|
||||
data = {'seed': -1}
|
||||
|
||||
return render_template('index.html', data=data)
|
||||
session["generator"] = WebGenerator(CRED_FILE)
|
||||
session["seed"] = seed
|
||||
session["story_manager"] = CachedStoryManager(generator, 0, session["seed"], CRED_FILE)
|
||||
|
||||
# Shows about. (Should also link to paper when published)
|
||||
@app.route('/about.html')
|
||||
def about():
|
||||
return render_template('about.html')
|
||||
|
||||
|
||||
# Bread and butter of app, updates story and returns based on choice
|
||||
@app.route('/choose', methods=['POST'])
|
||||
def story_request():
|
||||
pass
|
||||
@app.route('/generate', methods=['POST'])
|
||||
def generate():
|
||||
print("Entered generate")
|
||||
|
||||
if "story_manager" not in session:
|
||||
print("not initialized")
|
||||
seed = np.random.randint(100)
|
||||
story_init(session, seed)
|
||||
story_manager = session["story_manager"]
|
||||
possible_actions = story_manager.get_possible_actions()
|
||||
string_list = [str(story_manager.story), "\n\nOptions:" + "\n"]
|
||||
for i, action in enumerate(possible_actions):
|
||||
string_list.append(str(i) + ") " + action)
|
||||
|
||||
response = "".join(string_list)
|
||||
|
||||
else:
|
||||
print("initialized")
|
||||
story_manager = session["story_manager"]
|
||||
action = request.form["action"]
|
||||
result, possible_actions = story_manager.act(action_choice)
|
||||
if result is None:
|
||||
response = "Invalid choice. Must be a number from 0 to 3. \n"
|
||||
else:
|
||||
string_list = [response]
|
||||
for i, action in enumerate(possible_actions):
|
||||
string_list.append(str(i) + ") " + action)
|
||||
response = "".join(string_list)
|
||||
|
||||
return response
|
||||
|
||||
# Routes to index
|
||||
@app.route('/')
|
||||
def root():
|
||||
return render_template('index.html')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=8080)
|
||||
+19
-17
@@ -2,12 +2,12 @@ start_text = "<span id='a'>Adventurer@AIDungeon</span>:<span id='b'>~</span><spa
|
||||
|
||||
// Used to control the terminal like screen typing
|
||||
var Typer={
|
||||
text: null,
|
||||
inputStr: "",
|
||||
text:null,
|
||||
inputStr:"",
|
||||
index:0,
|
||||
speed:2,
|
||||
acceptInput: false,
|
||||
inputReady: false,
|
||||
acceptInput:false,
|
||||
inputReady:false,
|
||||
|
||||
content:function(){
|
||||
return $("#console").html()
|
||||
@@ -50,9 +50,9 @@ var Typer={
|
||||
|
||||
},
|
||||
|
||||
|
||||
sendInput:function(){
|
||||
$.post("/generate", {Typer.inputStr}, receiveResponse)
|
||||
request = Typer.inputStr
|
||||
$.post("/generate", {action: request}, receiveResponse)
|
||||
Typer.inputStr = ""
|
||||
},
|
||||
|
||||
@@ -92,19 +92,20 @@ var Typer={
|
||||
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
onButtonClick:function(num){
|
||||
|
||||
document.getElementById('buttons').style.visibility='hidden';
|
||||
function onButtonClick(num){
|
||||
|
||||
if (acceptInput == true){
|
||||
acceptInput = false
|
||||
num = String(num)
|
||||
Typer.appendToText(num)
|
||||
Typer.inputStr = num
|
||||
Typer.sendInput
|
||||
}
|
||||
},
|
||||
document.getElementById('buttons').style.visibility='hidden';
|
||||
|
||||
if (acceptInput == true){
|
||||
acceptInput = false
|
||||
num = String(num)
|
||||
Typer.appendToText(num)
|
||||
Typer.inputStr = num
|
||||
Typer.sendInput
|
||||
}
|
||||
}
|
||||
|
||||
function receiveResponse(text){
|
||||
@@ -119,7 +120,8 @@ function start(){
|
||||
Typer.text = ""
|
||||
Typer.appendToText(start_text)
|
||||
Typer.startTyping()
|
||||
$.post("/generate", {""}, receiveResponse)
|
||||
request_str = ""
|
||||
$.post("/generate", {text: request_str}, receiveResponse)
|
||||
|
||||
console.log("Not mobile device");
|
||||
document.getElementById('buttons').style.visibility='hidden';
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
|
||||
<title>AI 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">
|
||||
var seed = {{ data.seed }}
|
||||
</script>
|
||||
<link rel="stylesheet" type="text/css" href="static/style.css">
|
||||
</head>
|
||||
<div class="topnav">
|
||||
|
||||
Reference in New Issue
Block a user