-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappBAK1.py
More file actions
61 lines (53 loc) · 1.75 KB
/
appBAK1.py
File metadata and controls
61 lines (53 loc) · 1.75 KB
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, render_template, request, redirect, url_for
from backend import output_to_text, preprocess_text, process_output, split_into_sentences, DictKeyCombine
from keras.models import load_model
from flask import Markup
class_names= ['BACKGROUND', 'CONCLUSIONS', 'METHODS', 'OBJECTIVE', 'RESULTS']
model = load_model('Models\\NLP_Sentence_Encoder_Model\\NLP_Sentence_Encoder_Model')
output = None
TextData = None
TEXT = None
result = None
def detect_words(text: str, words: list[str]):
for word in words:
if word in text:
return f"<h2>{word}</h2>"
return ""
def output_to_html(output):
if not output:
return ""
html = ""
for sentence in output:
for key, value in sentence.items():
html += f"<h2>{key}</h2> <br> <p>{value}</p> <br>"
return html
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def home():
text = ""
if request.method == 'POST':
text = request.form['text']
main_API(text=text)
return render_template('index.html', title='PubMed 200K', txt=Markup(output_to_html(TEXT)))
def main_API(text):
global ERRORMESSAGE
global output
global TEXT
global result
if request.method == 'POST':
try:
data = preprocess_text(text)
output = process_output(
data = data,
sentences = split_into_sentences(text),
class_names = class_names,
model = model
)
result = DictKeyCombine(output)
clases, TEXT = output_to_text(output, class_names)
return ""
except Exception as e:
ERRORMESSAGE = str(e)
return ERRORMESSAGE
if __name__ == '__main__':
app.run(debug=True)