Nimzi commited on
Commit
9291ec2
·
verified ·
1 Parent(s): 62a3747

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -7
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 Model
13
- fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
 
 
14
 
15
  def classify_text(news_text):
16
- result = fake_news_pipeline(news_text)[0]
17
- label = result['label'].lower()
18
- score = result['score'] * 100
19
- return ("Fake" if label == "fake" else "Real"), round(score, 2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"])