-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
32 lines (27 loc) · 942 Bytes
/
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
from flask import Flask, request, jsonify
import json
from generate_questions import generate_question
from livereload import Server
app = Flask(__name__)
@app.route('/')
def index():
return app.send_static_file('index.html')
@app.route('/generate-questions', methods=['POST'])
def generate_questions_endpoint():
data = request.get_json()
context = data['context']
question_count = int(data['questionCount'])
questions, correctAnswers, distractor1, distractor2, distractor3= generate_question(context, question_count)
response = {
'questions': questions,
'correctAnswers': correctAnswers,
'distractor1': distractor1,
'distractor2': distractor2,
'distractor3': distractor3
}
return jsonify(response)
# if __name__ == '__main__':
# app.run(debug=False)
if __name__ == '__main__':
server = Server(app.wsgi_app)
server.serve()