Update app.py
Browse files
app.py
CHANGED
|
@@ -1,89 +1,3 @@
|
|
| 1 |
-
# import streamlit as st
|
| 2 |
-
# import numpy as np
|
| 3 |
-
# import cv2
|
| 4 |
-
# import tempfile
|
| 5 |
-
# import os
|
| 6 |
-
# from PIL import Image
|
| 7 |
-
|
| 8 |
-
# # ---- Page Configuration ----
|
| 9 |
-
# st.set_page_config(page_title="Fake & Deepfake Detection", layout="wide")
|
| 10 |
-
|
| 11 |
-
# st.title("π° Fake News & Deepfake Detection Tool")
|
| 12 |
-
# st.write("π Detect Fake News, Deepfake Images, and Videos using AI")
|
| 13 |
-
|
| 14 |
-
# # ---- Fake News Detection Section ----
|
| 15 |
-
# st.subheader("π Fake News Detection")
|
| 16 |
-
# news_input = st.text_area("Enter News Text:", "Type here...")
|
| 17 |
-
|
| 18 |
-
# if st.button("Check News"):
|
| 19 |
-
# st.write("π Processing...")
|
| 20 |
-
# st.success("β
Result: This news is FAKE.") # Replace with ML Model
|
| 21 |
-
|
| 22 |
-
# # ---- Deepfake Image Detection Section ----
|
| 23 |
-
# st.subheader("πΈ Deepfake Image Detection")
|
| 24 |
-
# uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "png", "jpeg"])
|
| 25 |
-
|
| 26 |
-
# def compress_image(image, quality=90, max_size=(300, 300)): # β
High clarity image
|
| 27 |
-
# img = Image.open(image).convert("RGB")
|
| 28 |
-
# img.thumbnail(max_size)
|
| 29 |
-
# temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".jpg")
|
| 30 |
-
# img.save(temp_file.name, "JPEG", quality=quality)
|
| 31 |
-
# return temp_file.name
|
| 32 |
-
|
| 33 |
-
# if uploaded_image is not None:
|
| 34 |
-
# compressed_image_path = compress_image(uploaded_image)
|
| 35 |
-
# st.image(compressed_image_path, caption="πΌοΈ Compressed & Clear Image", use_column_width=True)
|
| 36 |
-
# if st.button("Analyze Image"):
|
| 37 |
-
# st.write("π Processing...")
|
| 38 |
-
# st.error("β οΈ Result: This image is a Deepfake.") # Replace with model
|
| 39 |
-
|
| 40 |
-
# # ---- Deepfake Video Detection Section ----
|
| 41 |
-
# st.subheader("π₯ Deepfake Video Detection")
|
| 42 |
-
# uploaded_video = st.file_uploader("Upload a Video", type=["mp4", "avi", "mov"])
|
| 43 |
-
|
| 44 |
-
# def compress_video(video):
|
| 45 |
-
# temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
|
| 46 |
-
|
| 47 |
-
# with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
|
| 48 |
-
# temp_video.write(video.read())
|
| 49 |
-
# video_path = temp_video.name
|
| 50 |
-
|
| 51 |
-
# cap = cv2.VideoCapture(video_path)
|
| 52 |
-
|
| 53 |
-
# if not cap.isOpened():
|
| 54 |
-
# st.error("β Error: Unable to read video!")
|
| 55 |
-
# return None
|
| 56 |
-
|
| 57 |
-
# fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 58 |
-
|
| 59 |
-
# # β
New Resolution (100x80) & 15 FPS
|
| 60 |
-
# frame_width = 50
|
| 61 |
-
# frame_height = 80
|
| 62 |
-
# out = cv2.VideoWriter(temp_file.name, fourcc, 15.0, (frame_width, frame_height))
|
| 63 |
-
|
| 64 |
-
# while cap.isOpened():
|
| 65 |
-
# ret, frame = cap.read()
|
| 66 |
-
# if not ret:
|
| 67 |
-
# break
|
| 68 |
-
# frame = cv2.resize(frame, (frame_width, frame_height))
|
| 69 |
-
# out.write(frame)
|
| 70 |
-
|
| 71 |
-
# cap.release()
|
| 72 |
-
# out.release()
|
| 73 |
-
|
| 74 |
-
# return temp_file.name
|
| 75 |
-
|
| 76 |
-
# if uploaded_video is not None:
|
| 77 |
-
# st.video(uploaded_video) # β
ΩΩΨ±Ψ§Ω ΩΫΪΫΩ Ψ§ΩΎ ΩΩΪ ΫΩΩΫ Ϊ©Ϋ Ψ¨ΨΉΨ― Ψ―Ϊ©ΪΎΨ§Ψ¦ΫΪΊ
|
| 78 |
-
# compressed_video_path = compress_video(uploaded_video)
|
| 79 |
-
# if compressed_video_path:
|
| 80 |
-
# st.video(compressed_video_path) # β
Ϊ©Ω
ΩΎΨ±ΫΨ³Ϊ ΩΫΪΫΩ Ψ¨ΪΎΫ Ψ―Ϊ©ΪΎΨ§Ψ¦ΫΪΊ
|
| 81 |
-
# if st.button("Analyze Video"):
|
| 82 |
-
# st.write("π Processing...")
|
| 83 |
-
# st.warning("β οΈ Result: This video contains Deepfake elements.") # Replace with model
|
| 84 |
-
|
| 85 |
-
# st.markdown("πΉ **Developed for Fake News & Deepfake Detection Hackathon**")
|
| 86 |
-
|
| 87 |
import streamlit as st
|
| 88 |
import numpy as np
|
| 89 |
import cv2
|
|
@@ -321,56 +235,7 @@ if uploaded_image is not None:
|
|
| 321 |
else:
|
| 322 |
st.error(f"β οΈ Result: This image is a Deepfake. (Confidence: {result['score']:.2f})")
|
| 323 |
|
| 324 |
-
|
| 325 |
-
# st.subheader("π₯ Deepfake Video Detection")
|
| 326 |
-
# uploaded_video = st.file_uploader("Upload a Video", type=["mp4", "avi", "mov"])
|
| 327 |
-
|
| 328 |
-
# def detect_deepfake_video(video_path):
|
| 329 |
-
# cap = cv2.VideoCapture(video_path)
|
| 330 |
-
# frame_scores = []
|
| 331 |
-
# frame_count = 0
|
| 332 |
-
|
| 333 |
-
# while cap.isOpened():
|
| 334 |
-
# ret, frame = cap.read()
|
| 335 |
-
# if not ret:
|
| 336 |
-
# break
|
| 337 |
-
|
| 338 |
-
# if frame_count % 10 == 0: # ΫΨ± 10ΩΫΪΊ ΩΨ±ΫΩ
Ϊ©Ψ§ ΨͺΨ¬Ψ²ΫΫ Ϊ©Ψ±ΫΪΊ
|
| 339 |
-
# frame_path = "temp_frame.jpg"
|
| 340 |
-
# cv2.imwrite(frame_path, frame)
|
| 341 |
-
# result = detect_deepfake_image(frame_path)
|
| 342 |
-
# frame_scores.append(result["score"])
|
| 343 |
-
# os.remove(frame_path)
|
| 344 |
-
|
| 345 |
-
# frame_count += 1
|
| 346 |
-
|
| 347 |
-
# cap.release()
|
| 348 |
-
|
| 349 |
-
# if not frame_scores:
|
| 350 |
-
# return {"label": "UNKNOWN", "score": 0.0} # Ψ§Ϊ―Ψ± Ϊ©ΩΨ¦Ϋ ΩΨ±ΫΩ
ΩΎΨ±Ψ§Ψ³ΫΨ³ ΩΫ ΫΩ Ψ³Ϊ©Ϋ
|
| 351 |
-
|
| 352 |
-
# avg_score = np.mean(frame_scores)
|
| 353 |
-
# confidence = round(float(avg_score), 2)
|
| 354 |
-
# final_label = "FAKE" if avg_score > 0.5 else "REAL"
|
| 355 |
-
|
| 356 |
-
# return {"label": final_label, "score": confidence}
|
| 357 |
-
|
| 358 |
-
# if uploaded_video is not None:
|
| 359 |
-
# st.video(uploaded_video)
|
| 360 |
-
# temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
|
| 361 |
-
# with open(temp_file.name, "wb") as f:
|
| 362 |
-
# f.write(uploaded_video.read())
|
| 363 |
-
|
| 364 |
-
# if st.button("Analyze Video"):
|
| 365 |
-
# st.write("π Processing... Please wait.")
|
| 366 |
-
# result = detect_deepfake_video(temp_file.name)
|
| 367 |
-
|
| 368 |
-
# if result["label"] == "FAKE":
|
| 369 |
-
# st.error(f"β οΈ Deepfake Detected! This video appears to be FAKE. (Confidence: {result['score']:.2f})")
|
| 370 |
-
# elif result["label"] == "REAL":
|
| 371 |
-
# st.success(f"β
This video appears to be REAL. (Confidence: {1 - result['score']:.2f})")
|
| 372 |
-
# else:
|
| 373 |
-
# st.warning("β οΈ Unable to analyze the video. Please try a different file.")
|
| 374 |
st.subheader("π₯ Deepfake Video Detection")
|
| 375 |
|
| 376 |
# Upload video file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import numpy as np
|
| 3 |
import cv2
|
|
|
|
| 235 |
else:
|
| 236 |
st.error(f"β οΈ Result: This image is a Deepfake. (Confidence: {result['score']:.2f})")
|
| 237 |
|
| 238 |
+
# ---- Deepfake Video Detection Section ----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
st.subheader("π₯ Deepfake Video Detection")
|
| 240 |
|
| 241 |
# Upload video file
|