|
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() |
|
|