Update app.py
Browse files
app.py
CHANGED
@@ -1,57 +1,28 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline
|
3 |
from pytube import YouTube
|
|
|
4 |
import tempfile
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
st.
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
clip = VideoFileClip(tmp.name).subclip(0, min(10, yt.length))
|
30 |
-
frame = clip.get_frame(clip.duration / 2)
|
31 |
-
image = Image.fromarray(frame)
|
32 |
-
return detect_image(image)
|
33 |
-
|
34 |
-
st.title("AI Media Verifier: Image & Video Authenticity")
|
35 |
-
|
36 |
-
option = st.radio("Choose input type:", ("Image", "Video"))
|
37 |
-
|
38 |
-
if option == "Image":
|
39 |
-
uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
|
40 |
-
if uploaded_image:
|
41 |
-
image = Image.open(uploaded_image)
|
42 |
-
st.image(image, caption="Uploaded Image", use_container_width=True)
|
43 |
-
with st.spinner("Analyzing image..."):
|
44 |
-
results = detect_image(uploaded_image)
|
45 |
-
st.success("Analysis Complete")
|
46 |
-
for res in results:
|
47 |
-
st.write(f"**{res['label']}**: {res['score']*100:.2f}%")
|
48 |
-
|
49 |
-
elif option == "Video":
|
50 |
-
video_url = st.text_input("Enter YouTube Video Link")
|
51 |
-
if video_url:
|
52 |
-
st.video(video_url)
|
53 |
-
with st.spinner("Analyzing video..."):
|
54 |
-
results = detect_video(video_url)
|
55 |
-
st.success("Video Analysis Complete")
|
56 |
-
for res in results:
|
57 |
-
st.write(f"**{res['label']}**: {res['score']*100:.2f}%")
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from pytube import YouTube
|
3 |
+
from transformers import pipeline
|
4 |
import tempfile
|
5 |
+
import os
|
6 |
+
|
7 |
+
st.title("Deepfake Video Detection")
|
8 |
+
video_url = st.text_input("Enter YouTube Video URL:")
|
9 |
+
if st.button("Submit") and video_url:
|
10 |
+
with st.spinner("Downloading and analyzing video..."):
|
11 |
+
try:
|
12 |
+
yt = YouTube(video_url)
|
13 |
+
stream = yt.streams.filter(file_extension='mp4', progressive=True).first()
|
14 |
+
temp_dir = tempfile.mkdtemp()
|
15 |
+
video_path = os.path.join(temp_dir, "video.mp4")
|
16 |
+
stream.download(output_path=temp_dir, filename="video.mp4")
|
17 |
+
|
18 |
+
model = pipeline("image-classification", model="facebook/deit-base-distilled-patch16-224")
|
19 |
+
results = model(video_path)
|
20 |
+
|
21 |
+
st.success("Analysis Complete")
|
22 |
+
st.write("Prediction:", results[0]['label'])
|
23 |
+
st.write("Confidence:", f"{results[0]['score'] * 100:.2f}%")
|
24 |
+
|
25 |
+
os.remove(video_path)
|
26 |
+
os.rmdir(temp_dir)
|
27 |
+
except Exception as e:
|
28 |
+
st.error(f"Error: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|