Nimzi commited on
Commit
28d0426
Β·
verified Β·
1 Parent(s): a906516

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -20
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 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):
@@ -48,7 +39,8 @@ def analyze_video(video_url):
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
 
 
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