-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
47 lines (35 loc) · 1.21 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
# backend -> frontend, frontend -> backend (jinja from Flask)
# from crypt import methods
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("/Summarise", methods=["GET", "POST"])
def Summarise():
if req.method == "POST":
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
headers = {"Authorization": f"Bearer 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"}
data = req.form["data"]
maxL = int(req.form["maxL"])
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.debug = True
app.run()