TruthLens commited on
Commit
cbdfbb1
·
verified ·
1 Parent(s): b1f6a8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -31
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="facebook/deit-base-distilled-patch16-224")
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- def detect_deepfake(image, model):
27
- results = model(image)
28
- return results
 
 
29
 
30
  def main():
31
- video_url = st.text_input("Enter YouTube Video URL:")
32
- if st.button("Analyze") and video_url:
33
- thumbnail = get_thumbnail(video_url)
34
- if thumbnail:
35
- st.image(thumbnail, caption="Video Thumbnail", use_container_width=True)
36
- model = load_model()
37
- results = detect_deepfake(thumbnail, model)
38
- st.subheader("Detection Results:")
39
- for res in results:
40
- st.write(f"{res['label']}: {res['score']:.4f}")
41
- else:
42
- st.warning("Unable to fetch thumbnail. Please check the video URL.")
 
 
 
 
 
 
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()