asad231's picture
Update app.py
62aecb5 verified
raw
history blame
2.95 kB
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...")
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=50, max_size=(100, 100)): # βœ… Better quality & small size
img = Image.open(image).convert("RGB")
img.thumbnail(max_size)
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...")
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')
# βœ… Further Reduce Video Resolution
frame_width = 200
frame_height = 120
out = cv2.VideoWriter(temp_file.name, fourcc, 12.0, (frame_width, frame_height)) # βœ… Lower FPS to 12
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...")
st.warning("⚠️ Result: This video contains Deepfake elements.") # Replace with model
st.markdown("πŸ”Ή **Developed for Fake News & Deepfake Detection Hackathon**")