File size: 1,714 Bytes
f200883
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
# fake_video_detector.py

import streamlit as st
import requests
from PIL import Image
from io import BytesIO
from transformers import pipeline

def extract_thumbnail_url(youtube_url):
    """Extracts the thumbnail URL from a YouTube video link."""
    video_id = youtube_url.split("v=")[-1].split("&")[0]
    return f"https://img.youtube.com/vi/{video_id}/maxresdefault.jpg"

def load_image(url):
    """Loads an image from a URL."""
    response = requests.get(url)
    if response.status_code == 200:
        return Image.open(BytesIO(response.content))
    return None

def main():
    st.title("🔎 YouTube Fake Video Detector")
    st.write("Enter a YouTube video link to detect if its thumbnail is AI-generated or manipulated.")

    youtube_url = st.text_input("YouTube Video Link")

    if youtube_url:
        thumbnail_url = extract_thumbnail_url(youtube_url)
        st.subheader("Thumbnail Preview:")
        image = load_image(thumbnail_url)

        if image:
            st.image(image, caption="Video Thumbnail", use_column_width=True)

            with st.spinner("Analyzing thumbnail..."):
                # Load a pretrained model for image classification (can be replaced with a custom model)
                model = pipeline("image-classification", model="nateraw/resnet50-oxford-flowers")
                results = model(thumbnail_url)

            st.subheader("Detection Results:")
            for result in results:
                st.write(f"**{result['label']}**: {result['score']*100:.2f}% confidence")
        else:
            st.error("Failed to load thumbnail. Please check the YouTube link.")

if __name__ == "__main__":
    main()