-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
39 lines (28 loc) · 1.01 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
import requests
from flask import Flask, render_template, url_for
from flask import request as req
app = Flask(__name__)
@app.route("/",methods=["GET", "POST"])
def Index():
return render_template("index.html")
@app.route("/Summarize", methods=["GET", "POST"])
def Summarize():
if req.method=="POST":
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
headers = {"Authorization": f"Bearer {API Token}"}
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()