import streamlit as st import requests from transformers import pipeline from PIL import Image import torchvision.transforms as transforms # Load a more accurate fake news detection model fake_news_pipeline = pipeline("text-classification", model="roberta-base-openai-detector") # Function to classify news text 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) # Function to verify news with Google Fact Check API def verify_news(news_text): search_url = f"https://toolbox.google.com/factcheck/explorer/search/{'+'.join(news_text.split())}" return search_url # Function to analyze images (Dummy function for now) 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!" # Streamlit UI st.set_page_config(page_title="Fake News Detector", layout="wide") st.title("📰 Fake News Detector") # Sidebar Navigation st.sidebar.title("Select Input Type") option = st.sidebar.radio("Choose an option", ["Text", "Image", "Video Link"]) # Input Sections col1, col2, col3 = st.columns(3) # Text Analysis Section with col1: st.subheader("📄 Text News Check") news_text = st.text_area("Enter the news content:", height=200) if st.button("Analyze News"): if not news_text.strip(): st.warning("Please enter some text.") else: result, accuracy = classify_text(news_text) verification_link = verify_news(news_text) if result == "Fake": st.error(f"❌ Likely **Fake News**! (Confidence: {accuracy}%)") else: st.success(f"✅ Likely **Real News**! (Confidence: {accuracy}%)") st.markdown(f"[🔎 Verify on Google Fact Check]({verification_link})") # Image Upload Section with col2: st.subheader("🖼️ Image News Check") 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.image(image, caption="Uploaded Image", use_column_width=True) st.info(analyze_image(image)) # Video Link Section with col3: st.subheader("🎥 Video News Check") 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.video(video_url) st.info("Video analysis feature coming soon!")