-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
88 lines (66 loc) · 2.76 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
from flask import Flask, render_template, request, send_from_directory, send_file
from utils.prac import *
from utils.knowledge_graph import generate_knowledge_graph
from utils.ques_generation.generate_questions import get_questions
from utils.domain_summarizer import get_domain_summary
import os
import random
app = Flask(__name__)
@app.route("/")
def home():
return render_template('home.html')
# ROUTES FOR SUMMARY GENERATION
@app.route("/revise")
def summary_page():
return render_template('revise.html')
@app.route("/generate_key", methods=['GET', 'POST'])
def generate_summary():
if request.method=='POST':
text_input = request.form['original_text']
result = ""
if str(text_input).strip()=="":
return render_template('key_points.html', result="Unable to generate summary :(", original=text_input)
choice = request.form['purpose']
if choice=="gen":
sentences = clean_text(text_input)
text_data = cnt_in_sent(sentences)
freq_list = freq_dict(sentences)
tf_scores = calc_TF(text_data, freq_list)
idf_scores = calc_IDF(text_data, freq_list)
tfidf_scores = calc_TFIDF(tf_scores, idf_scores)
sent_data = sent_scores(tfidf_scores, sentences, text_data)
result = summary(sent_data)
else:
result = get_domain_summary(text_input,choice)
return render_template('key_points.html', result=result, original=text_input)
# ROUTES FOR MIND MAP GENERATION
@app.route("/map", methods=['GET','POST'])
def map():
if request.method=='POST':
text = request.form['kg_text']
image_title = generate_knowledge_graph(text)
if image_title==False:
return render_template('mindmap.html')
else:
return render_template('mindmap.html', image_title=image_title)
else:
return render_template('map.html')
# view/download mindmap
@app.route('/<path:filename>', methods=['GET', 'POST'])
def view(filename):
image_dir = os.path.join(app.root_path, "/static/media/")
return send_from_directory(directory=image_dir, filename=filename.split("/")[-1],as_attachment=True,attachment_filename=filename.split("/")[-1])
# ROUTES FOR QUESTION GENERATION
@app.route("/question")
def question():
return render_template('question.html')
@app.route("/generate_questions", methods=['GET', 'POST'])
def generate_questions():
text_input = request.form['original_text']
question = get_questions(text_input)
if question == []:
return render_template('question_gen.html', original=text_input)
random.shuffle(question)
return render_template('question_gen.html', original=text_input, result=question)
if __name__ == '__main__':
app.run(debug = True)