import streamlit as st import requests from transformers import pipeline from PIL import Image import torch import torchvision.transforms as transforms import io # Load Fake News Detection Model from Hugging Face fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection") def classify_text(news_text): result = fake_news_pipeline(news_text)[0]['label'].lower() return "Fake" if result == "fake" else "Real" def analyze_image(image): # Convert image to tensor (Placeholder: Model should be updated with a real image classifier) transform = transforms.Compose([transforms.Resize((224, 224)), transforms.ToTensor()]) image_tensor = transform(image).unsqueeze(0) return "Image analysis feature coming soon!" def verify_news(news_text): search_url = f"https://www.google.com/search?q={'+'.join(news_text.split())}" return search_url # 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"]) 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_text"] = True st.experimental_rerun() elif option == "Image": uploaded_image = st.file_uploader("Upload a news image", type=["jpg", "png", "jpeg"]) if uploaded_image and st.button("Analyze Image"): image = Image.open(uploaded_image) st.session_state["news_image"] = image st.session_state["analyze_image"] = True st.experimental_rerun() elif option == "Video Link": video_url = st.text_input("Enter the video link:") if st.button("Analyze Video"): if not video_url.strip(): st.warning("Please enter a valid video link.") else: st.session_state["video_url"] = video_url st.session_state["analyze_video"] = True st.experimental_rerun() with tab2: if st.session_state.get("analyze_text", False): news_text = st.session_state.get("news_text", "") with st.spinner("Analyzing text..."): result = classify_text(news_text) verification_link = verify_news(news_text) if result == "Fake": st.error("❌ This news is likely **Fake**!", icon="⚠️") else: st.success("✅ This news is likely **Real**!", icon="✅") st.subheader("🔍 Verification & Trusted Sources") sources = ["https://www.bbc.com/news", "https://www.cnn.com", "https://www.reuters.com"] for link in sources: st.markdown(f"[🔗 {link}]({link})") st.markdown(f"[🔎 Verify on Google]({verification_link})") if st.session_state.get("analyze_image", False): image = st.session_state.get("news_image") st.image(image, caption="Uploaded Image", use_column_width=True) st.info(analyze_image(image)) if st.session_state.get("analyze_video", False): video_url = st.session_state.get("video_url", "") st.video(video_url) st.info("Video analysis feature coming soon!")