Last active
November 24, 2017 00:53
-
-
Save toshimasa-nanaki/0c27ea404fda45b871fc4ed81a6a7543 to your computer and use it in GitHub Desktop.
AIを作りたい1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>{{ title }}</title> | |
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> | |
</head> | |
<body> | |
<script> | |
$(document).ready(function(){ | |
$('#submit').on("click", function() { | |
$.ajax({ | |
url: "http://127.0.0.1:5000/robot", | |
type:'POST', | |
dataType: 'text', | |
data : {"reply": $("#reply").val()}, | |
timeout:10000, | |
}).done(function(data) { | |
$("ul").append('<li>' + data + '</li>'); | |
$('#submit').prop("disabled", false); | |
}).fail(function(XMLHttpRequest, textStatus, errorThrown) { | |
alert("error"); | |
$('#submit').prop("disabled", false); | |
}) | |
}); | |
}); | |
</script> | |
<table border="0"> | |
<tr> | |
<td align="right"><b> 返答:</b></td> | |
<td><input type="text" name="reply" id="reply"></td> | |
</tr> | |
</table> | |
<input type="button" value="Submit" id="submit"/> | |
<div id="list"> | |
<ul></ul> | |
</div> | |
<div id="detail"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template, request | |
from random import choice | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
return render_template('index.html', title='RSS') | |
RESPONSES = ['食べたい', '飲みたい', '触りたい', '舐めたい'] | |
@app.route('/robot', methods=['POST']) | |
def robot(): | |
name = "ポンコツ丸" | |
return name+":"+request.form['reply']+"ですね?承知しました。私はそれを" + choice(RESPONSES) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment