-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
63 lines (42 loc) · 1.43 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
from typing import Text
from flask import Flask, render_template, request, redirect
import flask
from model.TEXT_SUMMARIZATION_BERT import model_forward
#from requests import request
import requests
# Bash
# export FLASK_APP=application.py
# flask run
app = Flask(__name__)
#app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///data.db"
#app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
#db = SQLAlchemy(app)
#SERVER_URL = 'http://127.0.0.1:5000/'
"""
############### Model Start #####################
import torch
from transformers import pipeline
summarizer = pipeline("summarization")
def model_forward(article):
summary = ''
for i in range (int(len(article)/1024)):
summary+=summarizer(article[1024*(i-1):1024*i], max_length=100, min_length=50, do_sample=False)[0]
#print(summary['summary_text'])
return summary
############### Model End #################
"""
@app.route('/landing' )#, methods = ['GET','POST' ])
def landing():
return render_template("landing.html")
@app.route('/' , methods = ['GET','POST' ])
def index():
return render_template("index.html")
@app.route("/submit/", methods = ["POST"])
def submit_text():
if request.method == 'POST':
text = request.form['submit-textbox']
summary = model_forward(text)
print(summary)
return render_template("landing.html" , summary = summary)
if __name__ == 'main':
app.run(debug=True)