Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,50 @@
|
|
1 |
-
from pytube import YouTube
|
2 |
import streamlit as st
|
|
|
3 |
from transformers import pipeline
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
from io import BytesIO
|
7 |
|
8 |
-
st.set_page_config(page_title="Video Deepfake Detector", layout="centered")
|
9 |
-
st.title("🎥 Video Deepfake Detector")
|
10 |
-
|
11 |
-
@st.cache_data
|
12 |
-
def get_thumbnail(url):
|
13 |
-
try:
|
14 |
-
yt = YouTube(url)
|
15 |
-
response = requests.get(yt.thumbnail_url)
|
16 |
-
if response.status_code == 200:
|
17 |
-
return Image.open(BytesIO(response.content))
|
18 |
-
except Exception as e:
|
19 |
-
st.error(f"Error fetching thumbnail: {e}")
|
20 |
-
return None
|
21 |
-
|
22 |
@st.cache_resource
|
23 |
def load_model():
|
24 |
-
return pipeline("image-classification", model="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
def
|
27 |
-
|
28 |
-
|
|
|
|
|
29 |
|
30 |
def main():
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
st.
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
if __name__ == "__main__":
|
45 |
main()
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from yt_dlp import YoutubeDL
|
3 |
from transformers import pipeline
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
from io import BytesIO
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
@st.cache_resource
|
9 |
def load_model():
|
10 |
+
return pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch16")
|
11 |
+
|
12 |
+
def fetch_thumbnail(video_url):
|
13 |
+
ydl_opts = {
|
14 |
+
'skip_download': True,
|
15 |
+
'quiet': True,
|
16 |
+
'extract_flat': True,
|
17 |
+
'cookiefile': 'cookies.txt'
|
18 |
+
}
|
19 |
+
with YoutubeDL(ydl_opts) as ydl:
|
20 |
+
info = ydl.extract_info(video_url, download=False)
|
21 |
+
return info.get('title'), info.get('thumbnail')
|
22 |
|
23 |
+
def classify_thumbnail(model, thumbnail_url):
|
24 |
+
response = requests.get(thumbnail_url)
|
25 |
+
image = Image.open(BytesIO(response.content)).convert("RGB")
|
26 |
+
labels = ["real", "AI-generated", "manipulated", "deepfake"]
|
27 |
+
return model(image, candidate_labels=labels)
|
28 |
|
29 |
def main():
|
30 |
+
st.title("🎥 Video Integrity Checker")
|
31 |
+
video_url = st.text_input("Enter YouTube video URL:")
|
32 |
+
if st.button("Submit") and video_url:
|
33 |
+
try:
|
34 |
+
title, thumbnail = fetch_thumbnail(video_url)
|
35 |
+
st.success(f"Video Title: {title}")
|
36 |
+
if thumbnail:
|
37 |
+
st.image(thumbnail, caption="Video Thumbnail", use_container_width=True)
|
38 |
+
model = load_model()
|
39 |
+
with st.spinner("Analyzing..."):
|
40 |
+
results = classify_thumbnail(model, thumbnail)
|
41 |
+
st.subheader("Detection Results:")
|
42 |
+
for label, score in zip(results['labels'], results['scores']):
|
43 |
+
st.write(f"{label}: {score:.2%}")
|
44 |
+
else:
|
45 |
+
st.warning("No thumbnail found.")
|
46 |
+
except Exception as e:
|
47 |
+
st.error(f"Error: {e}")
|
48 |
|
49 |
if __name__ == "__main__":
|
50 |
main()
|