File size: 3,677 Bytes
62c311b
a7f66d4
81a136d
097294d
a7f66d4
a906516
 
 
62c311b
a906516
ea6e24c
107dbe8
a906516
a7f66d4
5bc427c
 
 
 
a7f66d4
ea6e24c
 
 
 
 
a906516
a7f66d4
 
 
a906516
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7f66d4
62c311b
7e55fba
 
 
ea6e24c
 
 
 
 
f1dc8a7
5ff1805
ea6e24c
f1dc8a7
ea6e24c
 
 
f1dc8a7
 
 
 
ea6e24c
 
 
 
 
 
 
 
a7c9258
f1dc8a7
 
ea6e24c
f1dc8a7
ea6e24c
f1dc8a7
 
a906516
 
a7c9258
ea6e24c
f1dc8a7
ea6e24c
f1dc8a7
ea6e24c
f1dc8a7
 
 
 
a906516
 
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
93
94
95
96
97
98
99
100
101
102
103
104
105
import streamlit as st
import requests
from transformers import pipeline
from PIL import Image
import torchvision.transforms as transforms
import torch
import cv2
import numpy as np

# Load Fake News Detection Model
fake_news_pipeline = pipeline("text-classification", model="roberta-base-openai-detector")

# Function to classify text news
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 for fake news
def analyze_image(image):
    transform = transforms.Compose([transforms.Resize((224, 224)), transforms.ToTensor()])
    image_tensor = transform(image).unsqueeze(0)

    # Convert to OpenCV format
    image_cv = np.array(image)
    image_cv = cv2.cvtColor(image_cv, cv2.COLOR_RGB2BGR)

    # Apply Fake Image Detection (Basic Example)
    edges = cv2.Canny(image_cv, 100, 200)
    edge_percentage = np.sum(edges) / (image_cv.shape[0] * image_cv.shape[1])

    if edge_percentage > 0.1:
        return "❌ This image might be **manipulated** or **deepfake**!"
    else:
        return "βœ… This image appears to be **authentic**."

# Function to analyze video metadata
def analyze_video(video_url):
    api_url = f"https://noembed.com/embed?url={video_url}"
    response = requests.get(api_url).json()

    if "title" in response:
        title = response["title"]
        source = response["provider_name"]
        return f"πŸŽ₯ Video Title: {title}\nπŸ”— Source: {source}"
    else:
        return "❌ Unable to fetch video details! Check if the link is correct."

# 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)
        result = analyze_image(image)
        st.info(result)

# 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)
            result = analyze_video(video_url)
            st.info(result)