import streamlit as st import yt_dlp import torch from transformers import pipeline st.set_page_config(page_title="Video Deepfake Detector", layout="centered") # Download video using yt-dlp def download_video(video_url, output_path="video.mp4"): ydl_opts = { 'format': 'best', 'outtmpl': output_path, 'quiet': True, } with yt_dlp.YoutubeDL(ydl_opts) as ydl: ydl.download([video_url]) return output_path # Load the deepfake detection model def load_model(): return pipeline("image-classification", model="microsoft/resnet-50") # Analyze video frames for deepfake detection def analyze_video(video_path, model): import cv2 cap = cv2.VideoCapture(video_path) frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) step = max(frame_count // 5, 1) results = [] for i in range(0, frame_count, step): cap.set(cv2.CAP_PROP_POS_FRAMES, i) ret, frame = cap.read() if not ret: continue rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) prediction = model(rgb_frame) results.append(prediction[0]) cap.release() return results # Streamlit interface st.title("🎥 Video Deepfake Detector") video_url = st.text_input("Enter YouTube Video URL:") if st.button("Submit") and video_url: with st.spinner("Downloading and analyzing video..."): try: video_path = download_video(video_url) model = load_model() predictions = analyze_video(video_path, model) st.success("Analysis Complete!") for idx, pred in enumerate(predictions): st.write(f"Frame {idx + 1}: {pred['label']} with confidence {pred['score']:.2f}") except Exception as e: st.error(f"Error: {e}")