Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,30 @@ import cv2
|
|
9 |
import numpy as np
|
10 |
from bs4 import BeautifulSoup
|
11 |
|
12 |
-
# Load Fake News Detection
|
13 |
-
|
|
|
|
|
14 |
|
15 |
def classify_text(news_text):
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
def analyze_image(image):
|
22 |
try:
|
@@ -75,7 +91,6 @@ with col1:
|
|
75 |
else:
|
76 |
st.warning("Please enter some text.")
|
77 |
|
78 |
-
|
79 |
with col2:
|
80 |
st.header("Image News Analysis")
|
81 |
uploaded_image = st.file_uploader("Upload a news image", type=["jpg", "png", "jpeg"])
|
|
|
9 |
import numpy as np
|
10 |
from bs4 import BeautifulSoup
|
11 |
|
12 |
+
# Load Fake News Detection Models
|
13 |
+
fake_news_pipeline_1 = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
|
14 |
+
fake_news_pipeline_2 = pipeline("text-classification", model="nlptown/bert-base-multilingual-uncased-sentiment")
|
15 |
+
fake_news_pipeline_3 = pipeline("text-classification", model="roberta-base-openai-detector")
|
16 |
|
17 |
def classify_text(news_text):
|
18 |
+
result1 = fake_news_pipeline_1(news_text)[0]
|
19 |
+
result2 = fake_news_pipeline_2(news_text)[0]
|
20 |
+
result3 = fake_news_pipeline_3(news_text)[0]
|
21 |
+
|
22 |
+
scores = {
|
23 |
+
"Fake": 0,
|
24 |
+
"Real": 0
|
25 |
+
}
|
26 |
+
|
27 |
+
for result in [result1, result2, result3]:
|
28 |
+
label = result['label'].lower()
|
29 |
+
score = result['score'] * 100
|
30 |
+
scores["Fake" if "fake" in label else "Real"] += score
|
31 |
+
|
32 |
+
final_label = "Fake" if scores["Fake"] > scores["Real"] else "Real"
|
33 |
+
final_score = round(max(scores.values()) / 3, 2)
|
34 |
+
|
35 |
+
return final_label, final_score
|
36 |
|
37 |
def analyze_image(image):
|
38 |
try:
|
|
|
91 |
else:
|
92 |
st.warning("Please enter some text.")
|
93 |
|
|
|
94 |
with col2:
|
95 |
st.header("Image News Analysis")
|
96 |
uploaded_image = st.file_uploader("Upload a news image", type=["jpg", "png", "jpeg"])
|