-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
50 lines (34 loc) · 1.26 KB
/
main.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
print('Hello')
from transformers import pipeline
from flask import Flask, redirect, url_for, request, render_template
import warnings
warnings.filterwarnings('ignore')
# Model Weight Load
summarizer = pipeline("summarization", model="t5-base", tokenizer="t5-base", framework="tf")
def summarize_text(text: str):
summary_text = summarizer(text, max_length=100, min_length=5, do_sample=False)[0]['summary_text']
print(summary_text)
return summary_text
app = Flask(__name__)
def before_request():
app.jinja_env.cache = {}
@app.route('/')
def welcome():
return render_template('start.html')
@app.route('/summary', methods=['POST', 'GET'])
def summary():
if request.method == 'POST':
text = request.form['raw_text']
print(text)
text_summary = summarize_text(text)
# return redirect(url_for('summary',text = text, summary=''))
return render_template('index.html', text=text, summary=text_summary)
else:
text = ''
return render_template('index.html', text=text, summary='')
if __name__ == '__main__':
# app.before_request(before_request)
app.jinja_env.auto_reload = True
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
app.run(debug=True)