-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
42 lines (37 loc) · 1.18 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
#Importing the Libraries
import numpy as np
from flask import Flask, request,render_template
from flask_cors import CORS
import os
import joblib
import pickle
import flask
import os
import newspaper
from newspaper import Article
import urllib
#Loading Flask and assigning the model variable
app = Flask(__name__)
CORS(app)
app=flask.Flask(__name__,template_folder='templates')
with open('model.pickle', 'rb') as handle:
model = pickle.load(handle)
@app.route('/')
def main():
return render_template('index.html')
#Receiving the input url from the user and using Web Scrapping to extract the news content
@app.route('/predict',methods=['GET','POST'])
def predict():
url =request.get_data(as_text=True)[5:]
url = urllib.parse.unquote(url)
article = Article(str(url))
article.download()
article.parse()
article.nlp()
news = article.summary
#Passing the news article to the model and returing whether it is Fake or Real
pred = model.predict([news])
return render_template('index.html', prediction_text='The news is "{}"'.format(pred[0]))
if __name__=="__main__":
port=int(os.environ.get('PORT',5000))
app.run(port=port,debug=True,use_reloader=False)