-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
40 lines (27 loc) · 1.04 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
from flask import Flask, render_template,url_for
import requests
from flask import request as req
app = Flask(__name__)
@app.route("/",methods = ["GET","POST"])
def Index():
return render_template('index.html')
@app.route('/summerize',methods = ["GET","POST"])
def summerize():
if req.method == "POST":
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
headers = {"Authorization": "Bearer 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"}
data = req.form["inputText"]
maxL =int(req.form["maxLength"])
minL= maxL//4
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
output = query({
"inputs": data,
"parameters":{"min_length":minL, "max_length":maxL},
})[0]
return render_template('index.html',result=output["summary_text"])
else:
return render_template("index.html")
if __name__ == '__main__':
app.run()