Spaces:
Sleeping
Sleeping
File size: 4,150 Bytes
62c311b a7f66d4 ff59733 81a136d 1e42e10 c8d1c47 71c7fc8 7be5b04 71c7fc8 7be5b04 1e42e10 71c7fc8 7be5b04 71c7fc8 5bc427c ff59733 5bc427c a7f66d4 71c7fc8 ff59733 1e42e10 ff59733 71c7fc8 ea6e24c 7be5b04 b6792a4 a7f66d4 7e55fba b6792a4 71c7fc8 b6792a4 71c7fc8 b6792a4 ff59733 b6792a4 ff59733 b6792a4 ff59733 a5b7aa4 b72f78f b6792a4 71c7fc8 b6792a4 71c7fc8 ff59733 1e42e10 ff59733 b6792a4 ff59733 b6792a4 71c7fc8 b6792a4 71c7fc8 b6792a4 ff59733 b6792a4 ff59733 b6792a4 ff59733 |
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 |
import streamlit as st
import requests
import torch
import torchvision.transforms as transforms
from transformers import pipeline
from deepface import DeepFace
from PIL import Image
import cv2
import numpy as np
from bs4 import BeautifulSoup
# Load Fake News Detection Model
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 = result['label'].lower()
score = result['score'] * 100
return ("Fake" if label == "fake" else "Real"), round(score, 2)
def analyze_image(image):
try:
analysis = DeepFace.analyze(image, actions=["emotion"])
dominant_emotion = analysis[0]["dominant_emotion"]
return "Fake" if dominant_emotion in ["fear", "surprise"] else "Real"
except Exception as e:
return "Error: " + str(e)
def analyze_video(video_path):
try:
cap = cv2.VideoCapture(video_path)
frame_count = 0
results = []
while cap.isOpened():
ret, frame = cap.read()
if not ret or frame_count >= 10:
break
image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
result = analyze_image(image)
results.append(result)
frame_count += 1
cap.release()
return "Fake" if results.count("Fake") > results.count("Real") else "Real"
except Exception as e:
return "Error: " + str(e)
def verify_news(news_text):
search_url = f"https://www.google.com/search?q={'+'.join(news_text.split())}"
sources = [
f"https://www.bbc.co.uk/search?q={'+'.join(news_text.split())}",
f"https://www.cnn.com/search?q={'+'.join(news_text.split())}",
f"https://www.reuters.com/search/news?blob={'+'.join(news_text.split())}",
f"https://www.factcheck.org/?s={'+'.join(news_text.split())}",
f"https://www.snopes.com/?s={'+'.join(news_text.split())}",
f"https://www.politifact.com/search/?q={'+'.join(news_text.split())}"
]
return search_url, sources
st.set_page_config(page_title="Fake News Detector", layout="wide")
st.title("📰 Fake News Detector")
col1, col2, col3 = st.columns(3)
with col1:
st.header("Text News Analysis")
news_text = st.text_area("Enter the news content to check:", height=200)
if st.button("Analyze News", key="text_analyze"):
if news_text.strip():
result, accuracy = classify_text(news_text)
verification_link, sources = verify_news(news_text)
st.write(f"**Result:** {result} (Accuracy: {accuracy}%)")
st.markdown(f"[Verify on Google]({verification_link})")
for source in sources:
st.markdown(f"[Check Source]({source})")
else:
st.warning("Please enter some text.")
with col2:
st.header("Image News Analysis")
uploaded_image = st.file_uploader("Upload a news image", type=["jpg", "png", "jpeg"])
if uploaded_image and st.button("Analyze Image", key="image_analyze"):
image = Image.open(uploaded_image)
result = analyze_image(image)
st.image(image, caption="Uploaded Image", use_column_width=True)
st.write(f"**Result:** {result}")
verification_link, sources = verify_news("Fake news image verification")
st.markdown(f"[Verify on Google]({verification_link})")
for source in sources:
st.markdown(f"[Check Source]({source})")
with col3:
st.header("Video News Analysis")
video_url = st.text_input("Enter the video link:")
if st.button("Analyze Video", key="video_analyze"):
if video_url.strip():
result = analyze_video(video_url)
st.video(video_url)
st.write(f"**Result:** {result}")
verification_link, sources = verify_news("Fake news video verification")
st.markdown(f"[Verify on Google]({verification_link})")
for source in sources:
st.markdown(f"[Check Source]({source})")
else:
st.warning("Please enter a valid video link.")
|