Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,11 +3,14 @@ import requests
|
|
3 |
from transformers import pipeline
|
4 |
from PIL import Image
|
5 |
import torchvision.transforms as transforms
|
|
|
|
|
|
|
6 |
|
7 |
-
# Load
|
8 |
fake_news_pipeline = pipeline("text-classification", model="roberta-base-openai-detector")
|
9 |
|
10 |
-
# Function to classify news
|
11 |
def classify_text(news_text):
|
12 |
result = fake_news_pipeline(news_text)[0]
|
13 |
label = result['label'].lower()
|
@@ -19,11 +22,35 @@ def verify_news(news_text):
|
|
19 |
search_url = f"https://toolbox.google.com/factcheck/explorer/search/{'+'.join(news_text.split())}"
|
20 |
return search_url
|
21 |
|
22 |
-
# Function to analyze images
|
23 |
def analyze_image(image):
|
24 |
transform = transforms.Compose([transforms.Resize((224, 224)), transforms.ToTensor()])
|
25 |
image_tensor = transform(image).unsqueeze(0)
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# Streamlit UI
|
29 |
st.set_page_config(page_title="Fake News Detector", layout="wide")
|
@@ -61,7 +88,8 @@ with col2:
|
|
61 |
if uploaded_image and st.button("Analyze Image"):
|
62 |
image = Image.open(uploaded_image)
|
63 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
64 |
-
|
|
|
65 |
|
66 |
# Video Link Section
|
67 |
with col3:
|
@@ -72,5 +100,5 @@ with col3:
|
|
72 |
st.warning("Please enter a valid video link.")
|
73 |
else:
|
74 |
st.video(video_url)
|
75 |
-
|
76 |
-
|
|
|
3 |
from transformers import pipeline
|
4 |
from PIL import Image
|
5 |
import torchvision.transforms as transforms
|
6 |
+
import torch
|
7 |
+
import cv2
|
8 |
+
import numpy as np
|
9 |
|
10 |
+
# Load Fake News Detection Model
|
11 |
fake_news_pipeline = pipeline("text-classification", model="roberta-base-openai-detector")
|
12 |
|
13 |
+
# Function to classify text news
|
14 |
def classify_text(news_text):
|
15 |
result = fake_news_pipeline(news_text)[0]
|
16 |
label = result['label'].lower()
|
|
|
22 |
search_url = f"https://toolbox.google.com/factcheck/explorer/search/{'+'.join(news_text.split())}"
|
23 |
return search_url
|
24 |
|
25 |
+
# Function to analyze images for fake news
|
26 |
def analyze_image(image):
|
27 |
transform = transforms.Compose([transforms.Resize((224, 224)), transforms.ToTensor()])
|
28 |
image_tensor = transform(image).unsqueeze(0)
|
29 |
+
|
30 |
+
# Convert to OpenCV format
|
31 |
+
image_cv = np.array(image)
|
32 |
+
image_cv = cv2.cvtColor(image_cv, cv2.COLOR_RGB2BGR)
|
33 |
+
|
34 |
+
# Apply Fake Image Detection (Basic Example)
|
35 |
+
edges = cv2.Canny(image_cv, 100, 200)
|
36 |
+
edge_percentage = np.sum(edges) / (image_cv.shape[0] * image_cv.shape[1])
|
37 |
+
|
38 |
+
if edge_percentage > 0.1:
|
39 |
+
return "β This image might be **manipulated** or **deepfake**!"
|
40 |
+
else:
|
41 |
+
return "β
This image appears to be **authentic**."
|
42 |
+
|
43 |
+
# Function to analyze video metadata
|
44 |
+
def analyze_video(video_url):
|
45 |
+
api_url = f"https://noembed.com/embed?url={video_url}"
|
46 |
+
response = requests.get(api_url).json()
|
47 |
+
|
48 |
+
if "title" in response:
|
49 |
+
title = response["title"]
|
50 |
+
source = response["provider_name"]
|
51 |
+
return f"π₯ Video Title: {title}\nπ Source: {source}"
|
52 |
+
else:
|
53 |
+
return "β Unable to fetch video details! Check if the link is correct."
|
54 |
|
55 |
# Streamlit UI
|
56 |
st.set_page_config(page_title="Fake News Detector", layout="wide")
|
|
|
88 |
if uploaded_image and st.button("Analyze Image"):
|
89 |
image = Image.open(uploaded_image)
|
90 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
91 |
+
result = analyze_image(image)
|
92 |
+
st.info(result)
|
93 |
|
94 |
# Video Link Section
|
95 |
with col3:
|
|
|
100 |
st.warning("Please enter a valid video link.")
|
101 |
else:
|
102 |
st.video(video_url)
|
103 |
+
result = analyze_video(video_url)
|
104 |
+
st.info(result)
|