File size: 3,662 Bytes
62c311b
a7f66d4
81a136d
097294d
a7f66d4
 
a7c9258
62c311b
a7f66d4
0e6d020
107dbe8
a7f66d4
 
 
 
 
 
 
 
 
 
 
 
 
 
62c311b
7e55fba
 
 
097294d
 
d006eb0
097294d
 
 
a7c9258
097294d
 
 
 
 
 
 
a7f66d4
 
a7c9258
097294d
a7f66d4
 
 
 
 
 
a7c9258
097294d
a7f66d4
097294d
 
a7f66d4
097294d
a7f66d4
 
 
7e55fba
097294d
a7f66d4
7febe8b
a7f66d4
 
 
097294d
a7f66d4
097294d
 
a7f66d4
097294d
a7f66d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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!")