-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
78 lines (55 loc) · 2.34 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
import os
from collections import OrderedDict, Counter
from flask import Flask, render_template, request, redirect, url_for
from rake import Rake, text
from summarizer import summarize
app = Flask(__name__)
def turn_tuple_to_dict(tuples):
dict_ = OrderedDict()
for tuple_ in tuples:
dict_[tuple_[0]] = tuple_[1]
return dict_
def flatten_values(input_):
'''
finds single words in keys of a dictionary
e.g. dict_ = {"man in moon": 3, "what's this: 5", "bivu": 4}
["what's", 'this', 'bivu', 'man', 'in', 'moon']
'''
if type(input_) == dict:
list_to_parse = input_.keys()
else:
list_to_parse = input_
final_word_list = []
for each_ in list_to_parse:
final_word_list += list(map(lambda x: x.strip(), each_.split(" ")))
return final_word_list
def get_common_words(keywords, sentences):
'''
get words that are comming using both rake and NLTK
keywords is a dictinary
sentences is a list of sentences
'''
words_from_keywords = flatten_values(keywords)
words_from_summaries = flatten_values(sentences)
common_words = [element for element in words_from_keywords if element in words_from_summaries]
common_words = list(map(lambda x: x.strip().lower(), common_words))
common_words_dict = Counter(common_words) # most_common(n)
return common_words_dict
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == "POST":
job_description = request.form["description"]
job_title = request.form["title"]
rake = Rake("all_stop_words.txt")
keyword_tuples = rake.run(job_description)
keyword_dict = turn_tuple_to_dict(keyword_tuples)
important_sentences = summarize(job_title, job_description)
common_words = get_common_words(keyword_dict, important_sentences)
return render_template("results.html",
keywords=keyword_dict,
summaries=important_sentences,
common_words = common_words)
return render_template('index.html')
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port, debug=True)