-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
61 lines (52 loc) · 2.05 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
from flask import Flask, request, render_template
from traitement import *
app = Flask(__name__)
def highlight_entities(content, entities):
highlighted_content = ""
index = 0
for word, iob, ent_type in entities:
if iob == "B":
highlighted_content += content[index:word.idx] + f'<mark class="{ent_type}">{word.text}</mark>'
index = word.idx + len(word.text)
else:
continue
highlighted_content += content[index:]
return highlighted_content
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == "GET":
content = "Voici un simple test de madagascar"
data = {
'content': content,
'space': count_space(content),
'caractere': count_caractere(content),
'word': count_word(content),
'keyword': find_keyword(content, count_word(content)),
'sentence': get_sentence(content),
'paragraph': count_paragraphs(content),
'ner': ner(content),
'nbverbs':len(verbs(content)),
'verb_occurence': verb_occurence(content),
}
return render_template('index.html', content=data)
if request.method == 'POST':
file = request.files['file']
content = file.read().decode('utf-8')
data = {
'content': content,
'space': count_space(content),
'caractere': count_caractere(content),
'word': count_word(content),
'keyword': find_keyword(content, count_word(content)),
'sentence': get_sentence(content),
'paragraph': count_paragraphs(content),
'ner': ner(content),
'nbverbs':len(verbs(content)),
'verb_occurence': verb_occurence(content),
}
highlighted_content = highlight_entities(content, data['ner'])
data['highlighted_content'] = highlighted_content
return render_template('index.html', content=data)
return render_template('index.html', content=data)
if __name__ == '__main__':
app.run()