VidGuard / app.py
TruthLens's picture
Update app.py
b1f6a8b verified
raw
history blame
1.43 kB
from pytube import YouTube
import streamlit as st
from transformers import pipeline
from PIL import Image
import requests
from io import BytesIO
st.set_page_config(page_title="Video Deepfake Detector", layout="centered")
st.title("🎥 Video Deepfake Detector")
@st.cache_data
def get_thumbnail(url):
try:
yt = YouTube(url)
response = requests.get(yt.thumbnail_url)
if response.status_code == 200:
return Image.open(BytesIO(response.content))
except Exception as e:
st.error(f"Error fetching thumbnail: {e}")
return None
@st.cache_resource
def load_model():
return pipeline("image-classification", model="facebook/deit-base-distilled-patch16-224")
def detect_deepfake(image, model):
results = model(image)
return results
def main():
video_url = st.text_input("Enter YouTube Video URL:")
if st.button("Analyze") and video_url:
thumbnail = get_thumbnail(video_url)
if thumbnail:
st.image(thumbnail, caption="Video Thumbnail", use_container_width=True)
model = load_model()
results = detect_deepfake(thumbnail, model)
st.subheader("Detection Results:")
for res in results:
st.write(f"{res['label']}: {res['score']:.4f}")
else:
st.warning("Unable to fetch thumbnail. Please check the video URL.")
if __name__ == "__main__":
main()