import streamlit as st import requests from transformers import pipeline from PIL import Image import torch import torchvision.transforms as transforms # 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 = result['label'].lower() score = result['score'] * 100 # Convert to percentage return ("Fake" if label == "fake" else "Real"), round(score, 2) def analyze_image(image): 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") # Dividing Input Section col1, col2, col3 = st.columns(3) # Text Input Section with col1: st.subheader("📄 Enter Text") news_text = st.text_area("Enter the news content to check:", height=150) analyze_text_clicked = st.button("Analyze News") if analyze_text_clicked: if not news_text.strip(): st.warning("Please enter some text.") else: result, accuracy = classify_text(news_text) st.session_state["news_text"] = news_text st.session_state["result_text"] = result st.session_state["accuracy_text"] = accuracy # Image Upload Section with col2: st.subheader("🖼️ Upload Image") uploaded_image = st.file_uploader("Upload a news image", type=["jpg", "png", "jpeg"]) analyze_image_clicked = st.button("Analyze Image") if uploaded_image and analyze_image_clicked: image = Image.open(uploaded_image) st.session_state["news_image"] = image st.image(image, caption="Uploaded Image", use_column_width=True) st.info(analyze_image(image)) # Video Link Input Section with col3: st.subheader("🎥 Enter Video Link") video_url = st.text_input("Enter the video link:") analyze_video_clicked = st.button("Analyze Video") if analyze_video_clicked: if not video_url.strip(): st.warning("Please enter a valid video link.") else: st.session_state["video_url"] = video_url st.video(video_url) st.info("Video analysis feature coming soon!") # Results Section st.subheader("📊 Analysis Results") if "result_text" in st.session_state: result = st.session_state.get("result_text") accuracy = st.session_state.get("accuracy_text") verification_link = verify_news(st.session_state.get("news_text")) if result == "Fake": st.error(f"❌ This news is likely **Fake**! (Accuracy: {accuracy}%)", icon="⚠️") else: st.success(f"✅ This news is likely **Real**! (Accuracy: {accuracy}%)", icon="✅") st.subheader("🔍 Verification & Trusted Sources") sources = [ "https://www.bbc.com/news", "https://www.cnn.com", "https://www.reuters.com", "https://factcheck.org", "https://www.snopes.com", "https://www.politifact.com", "https://deepfake-o-meter.ai", "https://huggingface.co/models?pipeline_tag=text-classification" ] for link in sources: st.markdown(f"[🔗 {link}]({link})") st.markdown(f"[🔎 Verify on Google]({verification_link})")