File size: 3,079 Bytes
39abc8d 56e3c29 97e3cb7 39abc8d dbd5cd3 51b55ad 97e3cb7 51b55ad 97e3cb7 51b55ad 97e3cb7 51b55ad 97e3cb7 39abc8d 97e3cb7 39abc8d dbd5cd3 97e3cb7 dbd5cd3 97e3cb7 39abc8d 97e3cb7 39abc8d dbd5cd3 97e3cb7 dbd5cd3 39abc8d 97e3cb7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
import streamlit as st
import numpy as np
import cv2
import tempfile
import os
from PIL import Image
# ---- Page Configuration ----
st.set_page_config(page_title="Fake & Deepfake Detection", layout="wide")
st.title("π° Fake News & Deepfake Detection Tool")
st.write("π Detect Fake News, Deepfake Images, and Videos using AI")
# ---- Fake News Detection Section ----
st.subheader("π Fake News Detection")
news_input = st.text_area("Enter News Text:", "Type here...")
if st.button("Check News"):
st.write("π Processing...")
# Fake news detection logic (Placeholder)
st.success("β
Result: This news is FAKE.") # Replace with ML Model
# ---- Deepfake Image Detection Section ----
st.subheader("πΈ Deepfake Image Detection")
uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "png", "jpeg"])
def compress_image(image, quality=30, max_size=(500, 500)):
img = Image.open(image).convert("RGB")
img.thumbnail(max_size) # Resize while keeping aspect ratio
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".jpg")
img.save(temp_file.name, "JPEG", quality=quality)
return temp_file.name
if uploaded_image is not None:
compressed_image_path = compress_image(uploaded_image)
st.image(compressed_image_path, caption="πΌοΈ Compressed Image", use_column_width=True)
if st.button("Analyze Image"):
st.write("π Processing...")
# Deepfake detection logic (Placeholder)
st.error("β οΈ Result: This image is a Deepfake.") # Replace with model
# ---- Deepfake Video Detection Section ----
st.subheader("π₯ Deepfake Video Detection")
uploaded_video = st.file_uploader("Upload a Video", type=["mp4", "avi", "mov"])
def compress_video(video):
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
temp_video.write(video.read())
video_path = temp_video.name
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
st.error("β Error: Unable to read video!")
return None
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
# β
Reduce resolution to 480p
frame_width = 640
frame_height = 480
out = cv2.VideoWriter(temp_file.name, fourcc, 20.0, (frame_width, frame_height))
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame = cv2.resize(frame, (frame_width, frame_height))
out.write(frame)
cap.release()
out.release()
return temp_file.name
if uploaded_video is not None:
compressed_video_path = compress_video(uploaded_video)
if compressed_video_path:
st.video(compressed_video_path)
if st.button("Analyze Video"):
st.write("π Processing...")
# Deepfake video detection logic (Placeholder)
st.warning("β οΈ Result: This video contains Deepfake elements.") # Replace with model
st.markdown("πΉ **Developed for Fake News & Deepfake Detection Hackathon**")
|