-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
96 lines (74 loc) · 2.99 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from flask import Flask, render_template, flash, request, jsonify
from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField
from summarize import summarize
from gap_questions import create_gap_questions
from short_questions import create_short_questions
from mcq_questions import create_mcq_questions
import json
from flask_cors import CORS
import random
import math
# App config.
DEBUG = True
app = Flask(__name__)
CORS(app)
app.config.from_object(__name__)
app.config['SECRET_KEY'] = '7d441f27d441f27567d441f2b6176a'
class QuizGenerator(Form):
topic = TextField('Topic:')
article = TextField('Article:', validators=[validators.required(), validators.Length(min=100, message=(u'Must be atleast 100 words length'))])
@app.route("/generateGapQuestions", methods=['POST'])
def generateGapQuestions():
data = json.loads(request.data)
article = data['article']
summarized_text, summary_sentences = summarize(article)
gap_questions = []
for sentence in summary_sentences:
gap_question = create_gap_questions(sentence)
# create_mcq_questions(sentence)
if gap_question:
gap_questions.append(gap_question)
# print(gap_questions)
response = jsonify(gap_questions)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/generateMcqQuestions", methods=["POST"])
def generateMcqQuestions():
data = json.loads(request.data)
article = data['article']
summarized_text, summary_sentences = summarize(article)
mcq_questions = []
no_questions = 0
for sentence in summary_sentences:
mcq_question = create_mcq_questions(sentence)
if mcq_question:
no_questions += 1
mcq_questions.append(mcq_question)
print(no_questions)
response = jsonify(mcq_questions)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/generateShortQuestions", methods=['POST'])
def generateShortQuestions():
data = json.loads(request.data)
article = data['article']
summarized_text, summary_sentences = summarize(article)
short_questions = []
for sentence in summary_sentences:
short_question = create_short_questions(sentence)
if short_question:
short_questions.append(short_question)
response = jsonify(short_questions)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/summary", methods=['POST'])
def generateSummary():
data = json.loads(request.data)
article = data['article']
summarized_text, summary_sentences = summarize(article)
return (json.dumps(summarized_text), 200)
@app.route("/check", methods=['POST', 'GET'])
def checkApp():
return "working"
if __name__ == "__main__":
app.run()