-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
49 lines (40 loc) · 1.68 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
from flask import Flask, render_template, request, redirect, jsonify
from news import getArticlePredict, getSpecifArticle, getSpecifArticle
app = Flask(__name__)
@app.route('/', methods=['GET'])
def home():
return render_template('home.html')
@app.route('/aboutus')
def about_us():
return render_template('about_us.html')
@app.route('/result', methods=['POST', 'GET'])
def result():
if request.method == 'POST':
url = request.form.get("url")
if url:
news = getArticlePredict(url)
text = news['text']
print(len(text))
if(len(text) < 1000):
# return redirect('/home.html')
return render_template('home.html',value='INVALID',url=url)
else:
redirect('/result')
return render_template('result.html', url = url, article_title = news['title'], text = news['text'], image = news['image'], value=news['pred_result'], score=f" {news['pred_score']}%")
else:
return render_template('home.html', error = 'This form cannot be empty')
else:
return redirect('/')
@app.route('/newsfeed')
def news_feed():
articles = [None]*9
return render_template('news_feed.html', articles=articles)
@app.route('/getSpecificNews')
def getSpecificNews():
currentReal = request.args.get('cr', type = int)
currentFake = request.args.get('cf', type = int)
index = request.args.get('idx', type = int)
result = getSpecifArticle(currentReal,currentFake,index,maxReal=5,maxFake=4)
return jsonify(article = result[0], currentReal = result[1], currentFake = result[2], index = result[3])
if __name__== '__main__':
app.run(debug=True)