This repository has been archived by the owner on Jul 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.py
82 lines (75 loc) · 2.48 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
70
71
72
73
74
75
76
77
78
79
80
81
82
from flask import Flask
from flask import render_template
from flask import request
from flask import jsonify
from flask_sqlalchemy import SQLAlchemy
import os
app = Flask(__name__)
app.config.from_object(os.environ['APP_SETTINGS'])
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
from models import *
@app.route('/')
def index():
return render_template('hello.html')
@app.route('/hello')
def hello():
return render_template('hello.html')
@app.route('/haiku', methods=['POST'])
def haiku():
if request.is_xhr:
word = request.form['word']
processed_word = word.lower()
from runner import generateHaiku
result = generateHaiku(processed_word).split('\n')
line1 = result[0]
line2 = result[1]
line3 = result[2]
return jsonify(lineOne=line1, lineTwo=line2, lineThree=line3)
else:
word = request.form['word']
processed_word = word.lower()
from runner import generateHaiku
result = generateHaiku(processed_word).split('\n')
return render_template('show.html', word=processed_word, result=result)
@app.route('/train', methods=['POST'])
def train():
if request.is_xhr:
requestData = request.get_json()
update1 = requestData['train1']
update2 = requestData['train2']
update3 = requestData['train3']
from training import favorUnigram, unfavorUnigram, favorLine, unfavorLine
if update1 == "like1":
favorLine(requestData['lineOne'])
elif update1 == "dislike1":
unfavorLine(requestData['lineOne'])
if update2 == "like2":
favorLine(requestData['lineTwo'])
elif update2 == "dislike2":
unfavorLine(requestData['lineTwo'])
if update3 == "like3":
favorLine(requestData['lineThree'])
elif update3 == "dislike3":
unfavorLine(requestData['lineThree'])
return jsonify(result="thank you!")
else:
update1 = request.form['update1']
update2 = request.form['update2']
update3 = request.form['update3']
from training import favorUnigram, unfavorUnigram, favorLine, unfavorLine
if update1 == "like1":
favorLine(request.form['line1'])
elif update1 == "dislike1":
unfavorLine(request.form['line1'])
if update2 == "like2":
favorLine(request.form['line2'])
elif update2 == "dislike2":
unfavorLine(request.form['line2'])
if update3 == "like3":
favorLine(request.form['line3'])
elif update3 == dislike3:
unfavorLine(request.form['line3'])
return render_template('hello.html')
if __name__ == '__main__':
app.run()