Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
-
import cv2
|
4 |
import torch
|
5 |
import torchaudio
|
6 |
import torchvision
|
@@ -8,7 +7,7 @@ import tensorflow as tf
|
|
8 |
from transformers import pipeline
|
9 |
from PIL import Image
|
10 |
import requests
|
11 |
-
|
12 |
|
13 |
# Load a fake news detection model from Hugging Face
|
14 |
fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
|
@@ -20,21 +19,16 @@ st.title("π° Fake News Detector")
|
|
20 |
# Tabs for Input and Results
|
21 |
tab1, tab2 = st.tabs(["Input", "Results"])
|
22 |
|
23 |
-
# Function to fetch real news links based on
|
24 |
-
def fetch_real_news_links(
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
f"https://www.reuters.com/search/news?blob={query}",
|
29 |
-
f"https://www.snopes.com/?s={query}",
|
30 |
-
f"https://www.factcheck.org/search/?q={query}"
|
31 |
-
]
|
32 |
-
return search_urls
|
33 |
|
34 |
with tab1:
|
35 |
st.sidebar.title("Select Input Type")
|
36 |
option = st.sidebar.radio("Choose an option", ["Text", "Image", "Video Link"])
|
37 |
-
|
38 |
if option == "Text":
|
39 |
news_text = st.text_area("Enter the news content to check:", height=200)
|
40 |
if st.button("Analyze News"):
|
@@ -44,23 +38,21 @@ with tab1:
|
|
44 |
st.session_state["news_text"] = news_text
|
45 |
st.session_state["analyze"] = True
|
46 |
st.rerun()
|
47 |
-
|
48 |
elif option == "Image":
|
49 |
uploaded_file = st.file_uploader("Upload an image of a news article", type=["jpg", "png", "jpeg"])
|
50 |
if uploaded_file is not None:
|
51 |
image = Image.open(uploaded_file)
|
52 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
53 |
-
st.
|
54 |
-
|
55 |
-
|
56 |
elif option == "Video Link":
|
57 |
video_url = st.text_input("Enter a video news link to check")
|
58 |
if st.button("Analyze Video"):
|
59 |
if not video_url.strip():
|
60 |
st.warning("Please enter a valid URL.")
|
61 |
else:
|
62 |
-
st.
|
63 |
-
st.warning("β οΈ Video analysis is coming soon!")
|
64 |
|
65 |
with tab2:
|
66 |
if st.session_state.get("analyze", False):
|
@@ -69,25 +61,21 @@ with tab2:
|
|
69 |
# Check using Hugging Face model
|
70 |
hf_result = fake_news_pipeline(news_text)[0]['label'].lower()
|
71 |
|
72 |
-
# Display result
|
73 |
if hf_result == "fake":
|
74 |
st.error("β This news is likely **Fake**!", icon="β οΈ")
|
75 |
-
conclusion = "The analysis suggests that this news might be fabricated or misleading.
|
76 |
-
real_news_links = fetch_real_news_links(news_text[:50])
|
77 |
elif hf_result == "real":
|
78 |
st.success("β
This news is likely **Real**!", icon="β
")
|
79 |
conclusion = "The analysis indicates that this news appears to be credible and factual."
|
80 |
-
real_news_links = fetch_real_news_links(news_text[:50])
|
81 |
else:
|
82 |
st.info("π€ The result is uncertain. Please verify from trusted sources.")
|
83 |
-
conclusion = "
|
84 |
-
real_news_links = []
|
85 |
|
86 |
# Conclusion Section
|
87 |
st.subheader("π Conclusion")
|
88 |
st.write(conclusion)
|
89 |
|
90 |
# Display real news sources
|
91 |
-
st.subheader("π Related News
|
92 |
-
|
93 |
-
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
|
|
3 |
import torch
|
4 |
import torchaudio
|
5 |
import torchvision
|
|
|
7 |
from transformers import pipeline
|
8 |
from PIL import Image
|
9 |
import requests
|
10 |
+
import io
|
11 |
|
12 |
# Load a fake news detection model from Hugging Face
|
13 |
fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
|
|
|
19 |
# Tabs for Input and Results
|
20 |
tab1, tab2 = st.tabs(["Input", "Results"])
|
21 |
|
22 |
+
# Function to fetch real news links based on content
|
23 |
+
def fetch_real_news_links(news_text):
|
24 |
+
query = news_text.replace(" ", "+")
|
25 |
+
search_url = f"https://www.google.com/search?q={query}+site:bbc.com+OR+site:cnn.com+OR+site:reuters.com"
|
26 |
+
return search_url
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
with tab1:
|
29 |
st.sidebar.title("Select Input Type")
|
30 |
option = st.sidebar.radio("Choose an option", ["Text", "Image", "Video Link"])
|
31 |
+
|
32 |
if option == "Text":
|
33 |
news_text = st.text_area("Enter the news content to check:", height=200)
|
34 |
if st.button("Analyze News"):
|
|
|
38 |
st.session_state["news_text"] = news_text
|
39 |
st.session_state["analyze"] = True
|
40 |
st.rerun()
|
41 |
+
|
42 |
elif option == "Image":
|
43 |
uploaded_file = st.file_uploader("Upload an image of a news article", type=["jpg", "png", "jpeg"])
|
44 |
if uploaded_file is not None:
|
45 |
image = Image.open(uploaded_file)
|
46 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
47 |
+
st.info("π Text extraction from images is under development.")
|
48 |
+
|
|
|
49 |
elif option == "Video Link":
|
50 |
video_url = st.text_input("Enter a video news link to check")
|
51 |
if st.button("Analyze Video"):
|
52 |
if not video_url.strip():
|
53 |
st.warning("Please enter a valid URL.")
|
54 |
else:
|
55 |
+
st.info("π Video analysis is under development.")
|
|
|
56 |
|
57 |
with tab2:
|
58 |
if st.session_state.get("analyze", False):
|
|
|
61 |
# Check using Hugging Face model
|
62 |
hf_result = fake_news_pipeline(news_text)[0]['label'].lower()
|
63 |
|
|
|
64 |
if hf_result == "fake":
|
65 |
st.error("β This news is likely **Fake**!", icon="β οΈ")
|
66 |
+
conclusion = "The analysis suggests that this news might be fabricated or misleading."
|
|
|
67 |
elif hf_result == "real":
|
68 |
st.success("β
This news is likely **Real**!", icon="β
")
|
69 |
conclusion = "The analysis indicates that this news appears to be credible and factual."
|
|
|
70 |
else:
|
71 |
st.info("π€ The result is uncertain. Please verify from trusted sources.")
|
72 |
+
conclusion = "Further verification is recommended."
|
|
|
73 |
|
74 |
# Conclusion Section
|
75 |
st.subheader("π Conclusion")
|
76 |
st.write(conclusion)
|
77 |
|
78 |
# Display real news sources
|
79 |
+
st.subheader("π Related News Sources")
|
80 |
+
real_news_link = fetch_real_news_links(news_text)
|
81 |
+
st.markdown(f"[π Click here to verify]({real_news_link})")
|