Update app.py
Browse files
app.py
CHANGED
|
@@ -369,19 +369,10 @@ if uploaded_image is not None:
|
|
| 369 |
# ---- Deepfake Video Detection Section ----
|
| 370 |
st.subheader("🎥 Deepfake Video Detection")
|
| 371 |
|
| 372 |
-
|
| 373 |
-
video_url = st.text_input("
|
| 374 |
-
|
| 375 |
-
def download_video(url):
|
| 376 |
-
temp_video = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
|
| 377 |
-
response = requests.get(url, stream=True)
|
| 378 |
-
if response.status_code == 200:
|
| 379 |
-
with open(temp_video.name, "wb") as f:
|
| 380 |
-
for chunk in response.iter_content(chunk_size=8192):
|
| 381 |
-
f.write(chunk)
|
| 382 |
-
return temp_video.name
|
| 383 |
-
return None
|
| 384 |
|
|
|
|
| 385 |
def detect_deepfake_video(video_path):
|
| 386 |
cap = cv2.VideoCapture(video_path)
|
| 387 |
frame_scores = []
|
|
@@ -395,7 +386,7 @@ def detect_deepfake_video(video_path):
|
|
| 395 |
if frame_count % 10 == 0: # ہر 10ویں فریم کا تجزیہ کریں
|
| 396 |
frame_path = "temp_frame.jpg"
|
| 397 |
cv2.imwrite(frame_path, frame)
|
| 398 |
-
result = detect_deepfake_image(frame_path)
|
| 399 |
frame_scores.append(result["score"])
|
| 400 |
os.remove(frame_path)
|
| 401 |
|
|
@@ -412,25 +403,12 @@ def detect_deepfake_video(video_path):
|
|
| 412 |
|
| 413 |
return {"label": final_label, "score": confidence}
|
| 414 |
|
| 415 |
-
if
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
with open(temp_file.name, "wb") as f:
|
| 420 |
-
f.write(uploaded_video.read())
|
| 421 |
-
video_path = temp_file.name
|
| 422 |
-
elif video_url:
|
| 423 |
-
st.write("📥 Downloading video from URL...")
|
| 424 |
-
video_path = download_video(video_url)
|
| 425 |
-
if video_path:
|
| 426 |
-
st.video(video_path)
|
| 427 |
-
else:
|
| 428 |
-
st.error("⚠️ Failed to download video. Please check the URL and try again.")
|
| 429 |
-
video_path = None
|
| 430 |
-
|
| 431 |
-
if video_path and st.button("Analyze Video"):
|
| 432 |
st.write("🔍 Processing... Please wait.")
|
| 433 |
-
result = detect_deepfake_video(
|
| 434 |
|
| 435 |
if result["label"] == "FAKE":
|
| 436 |
st.error(f"⚠️ Deepfake Detected! This video appears to be FAKE. (Confidence: {result['score']:.2f})")
|
|
@@ -438,5 +416,5 @@ if uploaded_video is not None or video_url:
|
|
| 438 |
st.success(f"✅ This video appears to be REAL. (Confidence: {1 - result['score']:.2f})")
|
| 439 |
else:
|
| 440 |
st.warning("⚠️ Unable to analyze the video. Please try a different file.")
|
| 441 |
-
|
| 442 |
st.markdown("🔹 **Developed for Fake News & Deepfake Detection Hackathon**")
|
|
|
|
| 369 |
# ---- Deepfake Video Detection Section ----
|
| 370 |
st.subheader("🎥 Deepfake Video Detection")
|
| 371 |
|
| 372 |
+
# URL Input for Video
|
| 373 |
+
video_url = st.text_input("Enter Video URL")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
|
| 375 |
+
# Function to detect deepfake in video
|
| 376 |
def detect_deepfake_video(video_path):
|
| 377 |
cap = cv2.VideoCapture(video_path)
|
| 378 |
frame_scores = []
|
|
|
|
| 386 |
if frame_count % 10 == 0: # ہر 10ویں فریم کا تجزیہ کریں
|
| 387 |
frame_path = "temp_frame.jpg"
|
| 388 |
cv2.imwrite(frame_path, frame)
|
| 389 |
+
result = detect_deepfake_image(frame_path) # Deepfake detection function
|
| 390 |
frame_scores.append(result["score"])
|
| 391 |
os.remove(frame_path)
|
| 392 |
|
|
|
|
| 403 |
|
| 404 |
return {"label": final_label, "score": confidence}
|
| 405 |
|
| 406 |
+
if video_url:
|
| 407 |
+
st.video(video_url) # Show the video directly from URL
|
| 408 |
+
|
| 409 |
+
if st.button("Analyze Video"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
st.write("🔍 Processing... Please wait.")
|
| 411 |
+
result = detect_deepfake_video(video_url) # Pass the URL directly
|
| 412 |
|
| 413 |
if result["label"] == "FAKE":
|
| 414 |
st.error(f"⚠️ Deepfake Detected! This video appears to be FAKE. (Confidence: {result['score']:.2f})")
|
|
|
|
| 416 |
st.success(f"✅ This video appears to be REAL. (Confidence: {1 - result['score']:.2f})")
|
| 417 |
else:
|
| 418 |
st.warning("⚠️ Unable to analyze the video. Please try a different file.")
|
| 419 |
+
|
| 420 |
st.markdown("🔹 **Developed for Fake News & Deepfake Detection Hackathon**")
|