Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import torch
|
3 |
-
|
|
|
4 |
|
5 |
# Load model directly
|
6 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
@@ -8,11 +9,20 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
8 |
tokenizer = AutoTokenizer.from_pretrained("sofzcc/distilbert-base-uncased-fake-news-checker")
|
9 |
model = AutoModelForSequenceClassification.from_pretrained("sofzcc/distilbert-base-uncased-fake-news-checker")
|
10 |
|
11 |
-
def
|
12 |
-
article = Article(
|
13 |
article.download()
|
14 |
article.parse()
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
|
18 |
# Function to predict if news is real or fake
|
@@ -33,7 +43,7 @@ news_url = st.text_area("News URL", height=100)
|
|
33 |
|
34 |
if st.button("Evaluate"):
|
35 |
if news_url:
|
36 |
-
news_text =
|
37 |
prediction = predict_news(news_text)
|
38 |
st.write(f"The news article is predicted to be: **{prediction}**")
|
39 |
else:
|
|
|
1 |
import streamlit as st
|
2 |
import torch
|
3 |
+
import newspaper
|
4 |
+
import json
|
5 |
|
6 |
# Load model directly
|
7 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
|
9 |
tokenizer = AutoTokenizer.from_pretrained("sofzcc/distilbert-base-uncased-fake-news-checker")
|
10 |
model = AutoModelForSequenceClassification.from_pretrained("sofzcc/distilbert-base-uncased-fake-news-checker")
|
11 |
|
12 |
+
def extract_news_text(url):
|
13 |
+
article = newspaper.Article(url=url, language='en')
|
14 |
article.download()
|
15 |
article.parse()
|
16 |
+
|
17 |
+
article ={
|
18 |
+
"title": str(article.title),
|
19 |
+
"text": str(article.text),
|
20 |
+
"published_date": str(article.publish_date),
|
21 |
+
"keywords": article.keywords,
|
22 |
+
"summary": str(article.summary)
|
23 |
+
}
|
24 |
+
|
25 |
+
return article['text']
|
26 |
|
27 |
|
28 |
# Function to predict if news is real or fake
|
|
|
43 |
|
44 |
if st.button("Evaluate"):
|
45 |
if news_url:
|
46 |
+
news_text = extract_news_text(news_url)
|
47 |
prediction = predict_news(news_text)
|
48 |
st.write(f"The news article is predicted to be: **{prediction}**")
|
49 |
else:
|