File size: 1,777 Bytes
dc4f473
cbdfbb1
93dd3e3
b1f6a8b
 
 
93dd3e3
b1f6a8b
1dbeab5
cbdfbb1
 
 
 
 
 
 
 
 
 
 
 
1dbeab5
cbdfbb1
 
 
 
 
1dbeab5
b1f6a8b
cbdfbb1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93dd3e3
b1f6a8b
 
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
49
50
51
import streamlit as st
from yt_dlp import YoutubeDL
from transformers import pipeline
from PIL import Image
import requests
from io import BytesIO

@st.cache_resource
def load_model():
    return pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch16")

def fetch_thumbnail(video_url):
    ydl_opts = {
        'skip_download': True,
        'quiet': True,
        'extract_flat': True,
        'cookiefile': 'cookies.txt'
    }
    with YoutubeDL(ydl_opts) as ydl:
        info = ydl.extract_info(video_url, download=False)
        return info.get('title'), info.get('thumbnail')

def classify_thumbnail(model, thumbnail_url):
    response = requests.get(thumbnail_url)
    image = Image.open(BytesIO(response.content)).convert("RGB")
    labels = ["real", "AI-generated", "manipulated", "deepfake"]
    return model(image, candidate_labels=labels)

def main():
    st.title("🎥 Video Integrity Checker")
    video_url = st.text_input("Enter YouTube video URL:")
    if st.button("Submit") and video_url:
        try:
            title, thumbnail = fetch_thumbnail(video_url)
            st.success(f"Video Title: {title}")
            if thumbnail:
                st.image(thumbnail, caption="Video Thumbnail", use_container_width=True)
                model = load_model()
                with st.spinner("Analyzing..."):
                    results = classify_thumbnail(model, thumbnail)
                st.subheader("Detection Results:")
                for label, score in zip(results['labels'], results['scores']):
                    st.write(f"{label}: {score:.2%}")
            else:
                st.warning("No thumbnail found.")
        except Exception as e:
            st.error(f"Error: {e}")

if __name__ == "__main__":
    main()