Skip to content

Commit d127fe9

Browse files
authoredNov 25, 2021
Add files via upload
1 parent ccbb063 commit d127fe9

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
 

‎__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from flask import Flask
2+
from os import path
3+
from .views import views
4+
5+
def create_app():
6+
app = Flask(__name__)
7+
app.config['SECRET_KEY']="modi"
8+
app.register_blueprint(views,url_prefix="/")
9+
return app

‎app.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from news import create_app
2+
3+
if __name__==("__main__"):
4+
app = create_app()
5+
app.run(debug=True)
6+

‎views.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from flask import render_template, Blueprint, request, flash
2+
views = Blueprint("views", __name__)
3+
4+
5+
@views.route("/", methods=["POST", "GET"])
6+
@views.route("/home", methods=["POST", "GET"])
7+
def home():
8+
if request.method == 'POST':
9+
news = request.form.get("news")
10+
print(news)
11+
from flask import flash
12+
import pandas as pd
13+
import numpy as np
14+
from sklearn.feature_extraction.text import CountVectorizer
15+
from sklearn.model_selection import train_test_split
16+
from sklearn.naive_bayes import MultinomialNB
17+
from GoogleNews import GoogleNews
18+
19+
data = pd.read_csv("./fake_news.csv")
20+
print(data.head())
21+
x = np.array(data["title"])
22+
y = np.array(data["label"])
23+
24+
cv = CountVectorizer()
25+
x = cv.fit_transform(x)
26+
xtrain, xtest, ytrain, ytest = train_test_split(
27+
x, y, test_size=0.2, random_state=42)
28+
model = MultinomialNB()
29+
p=model.fit(xtrain, ytrain)
30+
31+
news_headline = news
32+
33+
34+
data = cv.transform([news_headline]).toarray()
35+
result = model.predict(data)
36+
37+
print(result)
38+
if result == ['FAKE']:
39+
print("fake")
40+
flash("The news is fake!", category='error')
41+
elif result == ['REAL']:
42+
print("true")
43+
flash("The news is \n real Trust me!", category='sucess')
44+
45+
return render_template("home.html")
46+
47+
@views.route("/chart")
48+
def chart():
49+
return render_template("chart.html")
50+
51+
52+
@views.route("/news",methods=["POST", "GET"])
53+
def news():
54+
c=""
55+
i=0
56+
if request.method == 'POST':
57+
import numpy as np
58+
from GoogleNews import GoogleNews
59+
news = request.form.get("news")
60+
print(news)
61+
news_headline = news
62+
googlenews = GoogleNews()
63+
googlenews = GoogleNews('en', 'd')
64+
65+
googlenews.search(news_headline)
66+
googlenews.get_news(news_headline)
67+
googlenews.getpage(1)
68+
69+
googlenews.result()
70+
a=googlenews.gettext()
71+
b=np.asarray(a)
72+
print(type(b))
73+
74+
c=b[0:6]
75+
return render_template("news.html",c=c,i=i)

0 commit comments

Comments
 (0)
Please sign in to comment.