File size: 4,824 Bytes
62c311b
a7f66d4
81a136d
28d0426
c8d1c47
 
62c311b
c8d1c47
 
107dbe8
a7f66d4
c8d1c47
5bc427c
 
 
 
a7f66d4
c8d1c47
 
 
 
 
 
 
 
 
ea6e24c
c8d1c47
 
ea6e24c
 
c8d1c47
 
 
 
 
 
 
 
 
 
 
 
a7f66d4
62c311b
7e55fba
 
 
c8d1c47
ea6e24c
 
 
c8d1c47
 
 
 
5ff1805
c8d1c47
 
 
ea6e24c
f1dc8a7
 
 
 
c8d1c47
 
ea6e24c
c8d1c47
 
f1dc8a7
ea6e24c
f1dc8a7
c8d1c47
 
 
 
a7c9258
c8d1c47
 
f1dc8a7
ea6e24c
f1dc8a7
 
 
c8d1c47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import streamlit as st
import requests
from transformers import pipeline
from deepface import DeepFace
from PIL import Image
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):
    """Classifies text as Fake or Real with accuracy."""
    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):
    """Analyzes image using DeepFace and provides a result."""
    try:
        analysis = DeepFace.analyze(image, actions=['emotion'])
        dominant_emotion = analysis[0]['dominant_emotion']
        return f"Analysis Complete - Dominant Emotion: {dominant_emotion}", 90.0  # Dummy Accuracy
    except Exception as e:
        return f"Error: {str(e)}", 0.0

def verify_news(news_text):
    """Generates a Google search link for verification."""
    search_url = f"https://www.google.com/search?q={'+'.join(news_text.split())}"
    return search_url

def check_video_fake_news(video_url):
    """Uses Google Fact-Check API for video verification."""
    api_url = f"https://factchecktools.googleapis.com/v1alpha1/claims:search?query={video_url}&key=YOUR_API_KEY"
    response = requests.get(api_url)
    
    if response.status_code == 200:
        data = response.json()
        if 'claims' in data:
            return "Fake", 85.0  # Fake News Detected (Dummy Value)
        else:
            return "Real", 92.0  # Seems Real (Dummy Value)
    return "Unknown", 0.0  # Could Not Verify

# Streamlit UI
st.set_page_config(page_title="Fake News Detector", layout="wide")
st.title("πŸ“° Fake News Detector")

# πŸ”Ή Sidebar for Input Selection
st.sidebar.title("Select Input Type")
option = st.sidebar.radio("Choose an option", ["Text", "Image", "Video Link"])

# πŸ”Ή Ensure session state variables are initialized
for key in ["analyze_text", "result_text", "accuracy_text", "analyze_image", "analyze_video", "news_image", "video_url"]:
    if key not in st.session_state:
        st.session_state[key] = None

# πŸ”Ή Text Input Section
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:
            result, accuracy = classify_text(news_text)
            st.session_state["result_text"] = result
            st.session_state["accuracy_text"] = accuracy

# πŸ”Ή Image Upload Section
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
        result, accuracy = analyze_image(image)
        st.session_state["result_text"] = result
        st.session_state["accuracy_text"] = accuracy

# πŸ”Ή Video Link Section
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
            result, accuracy = check_video_fake_news(video_url)
            st.session_state["result_text"] = result
            st.session_state["accuracy_text"] = accuracy

# πŸ”Ή Results Section
st.subheader("πŸ“Š Analysis Results")
if st.session_state["result_text"]:
    result = st.session_state["result_text"]
    accuracy = st.session_state["accuracy_text"]
    
    if result == "Fake":
        st.error(f"❌ This is likely **Fake News**! (Accuracy: {accuracy}%)", icon="⚠️")
    else:
        st.success(f"βœ… This is likely **Real News**! (Accuracy: {accuracy}%)", icon="βœ…")

    # πŸ”Ή Verification Sources
    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"
    ]
    for link in sources:
        st.markdown(f"[πŸ”— {link}]({link})")

    if option == "Text":
        verification_link = verify_news(st.session_state["result_text"])
        st.markdown(f"[πŸ”Ž Verify on Google]({verification_link})")

# πŸ”Ή Display Image if Uploaded
if st.session_state["news_image"]:
    st.image(st.session_state["news_image"], caption="Uploaded Image", use_column_width=True)

# πŸ”Ή Display Video if Entered
if st.session_state["video_url"]:
    st.video(st.session_state["video_url"])