Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,10 +2,11 @@ import streamlit as st
|
|
2 |
import requests
|
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")
|
@@ -22,23 +23,13 @@ def verify_news(news_text):
|
|
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
|
26 |
def analyze_image(image):
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
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):
|
@@ -48,7 +39,8 @@ def analyze_video(video_url):
|
|
48 |
if "title" in response:
|
49 |
title = response["title"]
|
50 |
source = response["provider_name"]
|
51 |
-
|
|
|
52 |
else:
|
53 |
return "β Unable to fetch video details! Check if the link is correct."
|
54 |
|
|
|
2 |
import requests
|
3 |
from transformers import pipeline
|
4 |
from PIL import Image
|
|
|
|
|
|
|
5 |
import numpy as np
|
6 |
+
import cv2
|
7 |
+
import torch
|
8 |
+
import torchvision.transforms as transforms
|
9 |
+
from deepface import DeepFace
|
10 |
|
11 |
# Load Fake News Detection Model
|
12 |
fake_news_pipeline = pipeline("text-classification", model="roberta-base-openai-detector")
|
|
|
23 |
search_url = f"https://toolbox.google.com/factcheck/explorer/search/{'+'.join(news_text.split())}"
|
24 |
return search_url
|
25 |
|
26 |
+
# Function to analyze deepfake images
|
27 |
def analyze_image(image):
|
28 |
+
try:
|
29 |
+
result = DeepFace.analyze(np.array(image), actions=['age', 'gender', 'race', 'emotion'])
|
30 |
+
return f"β
This image appears **real**! AI Analysis: {result}"
|
31 |
+
except Exception:
|
32 |
+
return "β This image might be **deepfake or manipulated**!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
# Function to analyze video metadata
|
35 |
def analyze_video(video_url):
|
|
|
39 |
if "title" in response:
|
40 |
title = response["title"]
|
41 |
source = response["provider_name"]
|
42 |
+
verification_link = verify_news(title)
|
43 |
+
return f"π₯ Video Title: {title}\nπ Source: {source}\n[π Verify this Video]({verification_link})"
|
44 |
else:
|
45 |
return "β Unable to fetch video details! Check if the link is correct."
|
46 |
|