-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fake_News_Det.py
39 lines (34 loc) · 1.28 KB
/
Fake_News_Det.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
from flask import Flask, render_template, request
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import PassiveAggressiveClassifier
import pickle
import pandas as pd
from sklearn.model_selection import train_test_split
app = Flask(__name__)
tfvect = TfidfVectorizer(stop_words='english', max_df=0.7)
loaded_model = pickle.load(open('model.pkl', 'rb'))
dataframe = pd.read_csv('news.csv')
x = dataframe['text']
y = dataframe['label']
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=0)
def fake_news_det(news):
tfid_x_train = tfvect.fit_transform(x_train)
tfid_x_test = tfvect.transform(x_test)
input_data = [news]
vectorized_input_data = tfvect.transform(input_data)
prediction = loaded_model.predict(vectorized_input_data)
return prediction
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
if request.method == 'POST':
message = request.form['message']
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)