-
Notifications
You must be signed in to change notification settings - Fork 355
/
my_model
59 lines (49 loc) · 1.67 KB
/
my_model
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
50
51
52
53
54
55
56
57
58
59
from flask import Flask, render_template, request
import pandas as pd
import sklearn
import itertools
import numpy as np
import seaborn as sb
import re
import nltk
import pickle
from sklearn.feature_extraction.text import TfidfVectorizer
from matplotlib import pyplot as plt
from sklearn.linear_model import PassiveAggressiveClassifier
from nltk.stem import WordNetLemmatizer
from nltk.corpus import stopwords
app = Flask(__name__,template_folder='./templates',static_folder='./static')
loaded_model = pickle.load(open('model.pkl', 'rb'))
lemmatizer = WordNetLemmatizer()
stpwrds = set(stopwords.words('english'))
tfidf_v = TfidfVectorizer()
corpus = []
def fake_news_det(news):
review = news
review = re.sub(r'[^a-zA-Z\s]', '', review)
review = review.lower()
review = nltk.word_tokenize(review)
for y in review :
if y not in stpwrds :
corpus.append(lemmatizer.lemmatize(y))
input_data = [' '.join(corpus)]
vectorized_input_data = tfidf_v.transform(input_data)
prediction = loaded_model.predict(vectorized_input_data)
if prediction[0] == 0:
print("Prediction of the News : Looking Fake⚠ News📰 ")
else:
print("Prediction of the News : Looking Real News📰 ")
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
if request.method == 'POST':
message = request.form['news']
pred = fake_news_det(message)
print(pred)
return render_template('index.html', prediction=pred)
else:
return render_template('index.html', prediction="Something went wrong")
if __name__ == '__main__':
app.run(debug=True)