Upload fake_video_detector.py
Browse files- fake_video_detector.py +47 -0
fake_video_detector.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# fake_video_detector.py
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import requests
|
| 5 |
+
from PIL import Image
|
| 6 |
+
from io import BytesIO
|
| 7 |
+
from transformers import pipeline
|
| 8 |
+
|
| 9 |
+
def extract_thumbnail_url(youtube_url):
|
| 10 |
+
"""Extracts the thumbnail URL from a YouTube video link."""
|
| 11 |
+
video_id = youtube_url.split("v=")[-1].split("&")[0]
|
| 12 |
+
return f"https://img.youtube.com/vi/{video_id}/maxresdefault.jpg"
|
| 13 |
+
|
| 14 |
+
def load_image(url):
|
| 15 |
+
"""Loads an image from a URL."""
|
| 16 |
+
response = requests.get(url)
|
| 17 |
+
if response.status_code == 200:
|
| 18 |
+
return Image.open(BytesIO(response.content))
|
| 19 |
+
return None
|
| 20 |
+
|
| 21 |
+
def main():
|
| 22 |
+
st.title("🔎 YouTube Fake Video Detector")
|
| 23 |
+
st.write("Enter a YouTube video link to detect if its thumbnail is AI-generated or manipulated.")
|
| 24 |
+
|
| 25 |
+
youtube_url = st.text_input("YouTube Video Link")
|
| 26 |
+
|
| 27 |
+
if youtube_url:
|
| 28 |
+
thumbnail_url = extract_thumbnail_url(youtube_url)
|
| 29 |
+
st.subheader("Thumbnail Preview:")
|
| 30 |
+
image = load_image(thumbnail_url)
|
| 31 |
+
|
| 32 |
+
if image:
|
| 33 |
+
st.image(image, caption="Video Thumbnail", use_column_width=True)
|
| 34 |
+
|
| 35 |
+
with st.spinner("Analyzing thumbnail..."):
|
| 36 |
+
# Load a pretrained model for image classification (can be replaced with a custom model)
|
| 37 |
+
model = pipeline("image-classification", model="nateraw/resnet50-oxford-flowers")
|
| 38 |
+
results = model(thumbnail_url)
|
| 39 |
+
|
| 40 |
+
st.subheader("Detection Results:")
|
| 41 |
+
for result in results:
|
| 42 |
+
st.write(f"**{result['label']}**: {result['score']*100:.2f}% confidence")
|
| 43 |
+
else:
|
| 44 |
+
st.error("Failed to load thumbnail. Please check the YouTube link.")
|
| 45 |
+
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
main()
|