File size: 3,251 Bytes
62c311b
 
81a136d
 
 
 
 
 
62c311b
81a136d
62c311b
 
7e55fba
81a136d
 
 
62c311b
 
7e55fba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
import cv2
import torch
import torchaudio
import torchvision
import tensorflow as tf
from transformers import pipeline
from groq import Groq
from openai import OpenAI

# Set up the Groq client
client = Groq(api_key=os.environ.get("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"))

# Load a fake news detection model from Hugging Face
fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")

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

# Sidebar for navigation
st.sidebar.title("Navigation")
option = st.sidebar.radio("Select Input Type", ["Text", "Image", "Video Link"])

# Function to fetch real news links (mocked for now)
def fetch_real_news_links():
    return ["https://www.bbc.com/news", "https://www.cnn.com", "https://www.reuters.com"]

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:
            with st.spinner("Analyzing..."):
                # Check using Groq API
                chat_completion = client.chat.completions.create(
                    messages=[{"role": "user", "content": f"Classify this news as Real or Fake: {news_text}"}],
                    model="llama-3.3-70b-versatile",
                    stream=False,
                )
                groq_result = chat_completion.choices[0].message.content.strip().lower()
                
                # Check using Hugging Face model
                hf_result = fake_news_pipeline(news_text)[0]['label'].lower()
                
                # Display result
                if "fake" in groq_result or hf_result == "fake":
                    st.error("❌ This news is likely **Fake**!", icon="⚠️")
                    st.markdown('<style>div.stAlert {background-color: #ffdddd;}</style>', unsafe_allow_html=True)
                elif "real" in groq_result or hf_result == "real":
                    st.success("βœ… This news is likely **Real**!", icon="βœ…")
                    st.markdown('<style>div.stAlert {background-color: #ddffdd;}</style>', unsafe_allow_html=True)
                else:
                    st.info("πŸ€” The result is uncertain. Please verify from trusted sources.")
                
                # Display real news sources
                st.subheader("πŸ”— Reliable News Sources")
                for link in fetch_real_news_links():
                    st.markdown(f"[πŸ”— {link}]({link})")

elif option == "Image":
    uploaded_file = st.file_uploader("Upload an image of news article", type=["jpg", "png", "jpeg"])
    if uploaded_file is not None:
        st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
        st.info("πŸ” Image analysis coming soon!")

elif option == "Video Link":
    video_url = st.text_input("Enter a video news link to check")
    if st.button("Analyze Video"):
        if not video_url.strip():
            st.warning("Please enter a valid URL.")
        else:
            st.info("πŸ” Video analysis coming soon!")