-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
69 lines (48 loc) · 1.56 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from flask import Flask, render_template, jsonify, request, session, send_from_directory
import json
from res import responce
app = Flask(__name__)
app.config["JSON_AS_ASCII"] = False
app.secret_key = 'secret'
@app.route('/')
def index():
session["flag"]=-1
session["model"]="Salieri"
session["chat"]=""
return render_template('index.html')
# /showにPOSTリクエストが送られたら処理してJSONを返す
@app.route('/chat', methods=['POST'])
def show():
flag=session["flag"]
txt=request.json['chatMessage']
model=session["model"]
chat=session["chat"]
res,choose,flag,model,chat,pose,lang=responce(txt,flag,model,chat)
#状態の更新
session["flag"]=flag
session["model"]=model
if chat!="":
if chat==0:
print("chat reset")
session["chat"]=""
else:
chat_sq=session["chat"]+chat
chat_list=chat_sq.split("You:")
#print(chat_list)
if len(chat_list)>4:
chat_sq="\nYou:"+chat_list[-3]+"You:"+chat_list[-2]+"You:"+chat_list[-1]
print("-----")
#print(chat_sq)
session["chat"]=chat_sq
return_json = {
"message": res,
"choose": choose,
"pose": pose,
"model": model,
"lang":lang
}
return jsonify(values=json.dumps(return_json))
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
# 0.0.0.0はすべてのアクセスを受け付けます。
# webブラウザーには、「localhost:5000」と入力