Nimzi's picture
Update app.py
873f8c6 verified
raw
history blame
3.63 kB
import streamlit as st
import os
import cv2
import torch
import torchaudio
import torchvision
import tensorflow as tf
from transformers import pipeline
# Load a fake news detection model from Hugging Face
fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
# Streamlit UI
st.set_page_config(page_title="Fake News Detector", layout="wide")
st.title("πŸ“° Fake News Detector")
# Tabs for Input and Results
tab1, tab2 = st.tabs(["Input", "Results"])
# Function to fetch real news links from various open sources
def fetch_real_news_links():
return [
"https://www.bbc.com/news",
"https://www.cnn.com",
"https://www.reuters.com",
"https://huggingface.co/datasets/misinformation",
"https://www.wildfire.ai/deepfake-news-dataset",
"https://www.snopes.com",
"https://www.factcheck.org"
]
with tab1:
st.sidebar.title("Select Input Type")
option = st.sidebar.radio("Choose an option", ["Text", "Image", "Video Link"])
if option == "Text":
news_text = st.text_area("Enter the news content to check:", height=200)
if st.button("Analyze News"):
if not news_text.strip():
st.warning("Please enter some text.")
else:
st.session_state["news_text"] = news_text
st.session_state["analyze"] = True
st.rerun()
elif option == "Image":
uploaded_file = st.file_uploader("Upload an image of a news article", type=["jpg", "png", "jpeg"])
if uploaded_file is not None:
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
st.info("πŸ” Image analysis coming soon!")
elif option == "Video Link":
video_url = st.text_input("Enter a video news link to check")
if st.button("Analyze Video"):
if not video_url.strip():
st.warning("Please enter a valid URL.")
else:
st.info("πŸ” Video analysis coming soon!")
with tab2:
if st.session_state.get("analyze", False):
news_text = st.session_state.get("news_text", "")
with st.spinner("Analyzing..."):
# Check using Hugging Face model
hf_result = fake_news_pipeline(news_text)[0]['label'].lower()
# Display result
if hf_result == "fake":
st.error("❌ This news is likely **Fake**!", icon="⚠️")
st.markdown('<style>div.stAlert {background-color: #ffdddd;}</style>', unsafe_allow_html=True)
conclusion = "The analysis suggests that this news might be fabricated or misleading. Please verify from credible sources."
elif hf_result == "real":
st.success("βœ… This news is likely **Real**!", icon="βœ…")
st.markdown('<style>div.stAlert {background-color: #ddffdd;}</style>', unsafe_allow_html=True)
conclusion = "The analysis indicates that this news appears to be credible and factual."
else:
st.info("πŸ€” The result is uncertain. Please verify from trusted sources.")
conclusion = "There is uncertainty in the classification. Further verification is recommended."
# Conclusion Section
st.subheader("πŸ“Œ Conclusion")
st.write(conclusion)
# Display real news sources
st.subheader("πŸ”— Reliable News Sources")
for link in fetch_real_news_links():
st.markdown(f"[πŸ”— {link}]({link})")