File size: 1,975 Bytes
dc4f473 b1f6a8b f31bdd1 b1f6a8b f31bdd1 67ddf1e f31bdd1 67ddf1e f31bdd1 93dd3e3 f31bdd1 |
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 |
import streamlit as st
from PIL import Image
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
import torch
import requests
from io import BytesIO
# Load deepfake detection model and extractor
model_name = "systemkc/deepfake-detection-v1" # Example model (replace if needed)
extractor = AutoFeatureExtractor.from_pretrained(model_name)
model = AutoModelForImageClassification.from_pretrained(model_name)
st.title("Deepfake Thumbnail Detector")
st.write("Upload a YouTube video link, and we’ll analyze the thumbnail to check for deepfakes.")
video_url = st.text_input("Enter YouTube Video Link:")
submit = st.button("Detect Deepfake")
if submit and video_url:
try:
video_id = video_url.split("v=")[-1].split("&")[0] if "v=" in video_url else video_url.split("/")[-1]
thumbnail_url = f"https://img.youtube.com/vi/{video_id}/maxresdefault.jpg"
response = requests.get(thumbnail_url)
response.raise_for_status()
image = Image.open(BytesIO(response.content))
st.image(image, caption="Video Thumbnail", use_container_width=True)
# Preprocess and predict
inputs = extractor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
predicted_class = torch.argmax(logits, dim=1).item()
confidence = torch.softmax(logits, dim=1)[0, predicted_class].item()
# Interpret results
if predicted_class == 1: # Assuming class 1 = Deepfake
st.error(f"🚨 **Deepfake Detected** (Confidence: {confidence:.2%})")
st.write("⚠️ Indicators of manipulation detected in the thumbnail.")
else:
st.success(f"✅ **No Deepfake Detected** (Confidence: {confidence:.2%})")
st.write("👍 Thumbnail appears authentic based on the model’s analysis.")
except Exception as e:
st.error(f"Error: {str(e)}")
|