-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
32 lines (24 loc) · 792 Bytes
/
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
from flask import Flask, render_template, request
import nltk
from newspaper import Article
app = Flask(__name__)
nltk.download('punkt')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/get_article', methods=['POST'])
def get_article():
url = request.form['url']
article = Article(url)
try:
article.download()
article.parse()
article.nlp()
title = article.title
authors = ', '.join(article.authors)
summary = article.summary
return render_template('index.html', title=title, authors=authors, summary=summary)
except Exception as e:
return render_template('index.html', error=str(e))
if __name__ == '__main__':
app.run(debug=True)