mirror of
https://github.com/wassname/Clover-Edition.git
synced 2026-09-09 11:13:26 +08:00
Added generate story request on front and back end
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
# [START gae_python37_render_template]
|
||||
import datetime
|
||||
|
||||
from flask import Flask, render_template
|
||||
from flask import Flask, render_template, request
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -27,6 +27,14 @@ def root():
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@app.route('/generate', methods=['POST'])
|
||||
def story_request():
|
||||
is_story_block = request.form["story_block"] # is it a full story block or just an action?
|
||||
prompt = request.form["prompt"] # given prompt
|
||||
|
||||
return "Greetings from the planet Zenon!"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# This is used when running locally only. When deploying to Google App
|
||||
# Engine, a webserver process such as Gunicorn will serve the app. This
|
||||
|
||||
+42
-32
@@ -1,16 +1,16 @@
|
||||
<!--
|
||||
Copyright (c) 2011 Sam Phippen <samphippen@googlemail.com>
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
@@ -18,12 +18,12 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Dungeon Dream</title>
|
||||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
|
||||
<style type="text/css">
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Dungeon Dream</title>
|
||||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
|
||||
<style type="text/css">
|
||||
body {
|
||||
background-color: #000
|
||||
}
|
||||
@@ -49,10 +49,10 @@ THE SOFTWARE.
|
||||
#b {
|
||||
color: #ff0096;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
var Typer={
|
||||
text: null,
|
||||
accessCountimer:null,
|
||||
@@ -68,16 +68,16 @@ THE SOFTWARE.
|
||||
Typer.text = Typer.text.slice(0, Typer.text.length-1);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
content:function(){
|
||||
return $("#console").html();// get console content
|
||||
},
|
||||
|
||||
|
||||
write:function(str){// append to console content
|
||||
$("#console").append(str);
|
||||
return false;
|
||||
},
|
||||
|
||||
|
||||
makeAccess:function(){//create Access Granted popUp FIXME: popup is on top of the page and doesn't show is the page is scrolled
|
||||
Typer.hidepop(); // hide all popups
|
||||
Typer.accessCount=0; //reset count
|
||||
@@ -96,15 +96,15 @@ THE SOFTWARE.
|
||||
$(document.body).prepend(ddiv);// prepend div to body
|
||||
return false;
|
||||
},
|
||||
|
||||
|
||||
hidepop:function(){// remove all existing popups
|
||||
$("#deni").remove();
|
||||
$("#gran").remove();
|
||||
},
|
||||
|
||||
|
||||
addText:function(key){//Main function to add the code
|
||||
if(key.keyCode==18){// key 18 = alt key
|
||||
Typer.accessCount++; //increase counter
|
||||
Typer.accessCount++; //increase counter
|
||||
if(Typer.accessCount>=3){// if it's presed 3 times
|
||||
Typer.makeAccess(); // make access popup
|
||||
}
|
||||
@@ -122,36 +122,36 @@ THE SOFTWARE.
|
||||
if(key.keyCode!=8){ // if key is not backspace
|
||||
Typer.index+=Typer.speed; // add to the index the speed
|
||||
}else{
|
||||
if(Typer.index>0) // else if index is not less than 0
|
||||
if(Typer.index>0) // else if index is not less than 0
|
||||
Typer.index-=Typer.speed;// remove speed for deleting text
|
||||
}
|
||||
var text=Typer.text.substring(0,Typer.index)// parse the text for stripping html enities
|
||||
var rtn= new RegExp("\n", "g"); // newline regex
|
||||
|
||||
|
||||
$("#console").html(text.replace(rtn,"<br/>"));// replace newline chars with br, tabs with 4 space and blanks with an html blank
|
||||
window.scrollBy(0,50); // scroll to make sure bottom is always visible
|
||||
}
|
||||
if ( key.preventDefault && key.keyCode != 122 ) { // prevent F11(fullscreen) from being blocked
|
||||
key.preventDefault()
|
||||
};
|
||||
};
|
||||
if(key.keyCode != 122){ // otherway prevent keys default behavior
|
||||
key.returnValue = false;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
updLstChr:function(){ // blinking cursor
|
||||
var cont=this.content(); // get console
|
||||
var cont=this.content(); // get console
|
||||
if(cont.substring(cont.length-1,cont.length)=="|") // if last char is the cursor
|
||||
$("#console").html($("#console").html().substring(0,cont.length-1)); // remove it
|
||||
else
|
||||
this.write("|"); // else write it
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function replaceUrls(text) {
|
||||
var http = text.indexOf("http://");
|
||||
var space = text.indexOf(".me ", http);
|
||||
if (space != -1) {
|
||||
if (space != -1) {
|
||||
var url = text.slice(http, space-1);
|
||||
return text.replace(url, "<a href=\"" + url + "\">" + url + "</a>");
|
||||
} else {
|
||||
@@ -161,7 +161,7 @@ function replaceUrls(text) {
|
||||
Typer.speed=3;
|
||||
Typer.file="static/dungeondream.txt";
|
||||
Typer.init();
|
||||
|
||||
|
||||
var timer = setInterval("t();", 30);
|
||||
function t() {
|
||||
Typer.addText({"keyCode": 123748});
|
||||
@@ -169,9 +169,19 @@ function t() {
|
||||
clearInterval(timer);
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
<div id="console"></div>
|
||||
|
||||
// request_story("Hello")
|
||||
|
||||
function request_story(prompt, callback){
|
||||
$.post("/generate", { story_block: true, prompt},
|
||||
function(data){
|
||||
alert(data)
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
<div id="console"></div>
|
||||
<script type="text/javascript">
|
||||
|
||||
var _gaq = _gaq || [];
|
||||
@@ -185,5 +195,5 @@ function t() {
|
||||
})();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user