Update app.py
Browse files
app.py
CHANGED
@@ -44,54 +44,61 @@
|
|
44 |
# st.markdown("πΉ **Developed for Fake News & Deepfake Detection Hackathon**")
|
45 |
|
46 |
|
47 |
-
import
|
48 |
import cv2
|
49 |
import numpy as np
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
if video_path is None:
|
69 |
-
return "β No video uploaded!"
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
44 |
# st.markdown("πΉ **Developed for Fake News & Deepfake Detection Hackathon**")
|
45 |
|
46 |
|
47 |
+
import streamlit as st
|
48 |
import cv2
|
49 |
import numpy as np
|
50 |
+
import tempfile
|
51 |
+
import os
|
52 |
+
from PIL import Image
|
53 |
+
|
54 |
+
def compress_image(image, quality=20):
|
55 |
+
img = Image.open(image)
|
56 |
+
img = img.convert("RGB")
|
57 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".jpg")
|
58 |
+
img.save(temp_file.name, "JPEG", quality=quality)
|
59 |
+
return temp_file.name
|
60 |
+
|
61 |
+
def compress_video(video):
|
62 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
|
63 |
+
cap = cv2.VideoCapture(video)
|
64 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
65 |
+
frame_width = int(cap.get(3) // 2)
|
66 |
+
frame_height = int(cap.get(4) // 2)
|
67 |
+
out = cv2.VideoWriter(temp_file.name, fourcc, 20.0, (frame_width, frame_height))
|
68 |
|
69 |
+
while cap.isOpened():
|
70 |
+
ret, frame = cap.read()
|
71 |
+
if not ret:
|
72 |
+
break
|
73 |
+
frame = cv2.resize(frame, (frame_width, frame_height))
|
74 |
+
out.write(frame)
|
|
|
|
|
75 |
|
76 |
+
cap.release()
|
77 |
+
out.release()
|
78 |
+
return temp_file.name
|
79 |
+
|
80 |
+
st.title("π΅οΈββοΈ Fake News & Deepfake Detection Tool")
|
81 |
+
|
82 |
+
st.sidebar.header("Upload your file")
|
83 |
+
option = st.sidebar.radio("Select file type", ["Image", "Video", "Text"])
|
84 |
+
|
85 |
+
if option == "Image":
|
86 |
+
uploaded_file = st.sidebar.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
87 |
+
if uploaded_file is not None:
|
88 |
+
compressed_path = compress_image(uploaded_file)
|
89 |
+
image = Image.open(compressed_path)
|
90 |
+
st.image(image, caption="Compressed Image", use_column_width=True)
|
91 |
+
st.success("β
Image uploaded and compressed successfully!")
|
92 |
+
|
93 |
+
elif option == "Video":
|
94 |
+
uploaded_file = st.sidebar.file_uploader("Upload a video", type=["mp4", "avi", "mov"])
|
95 |
+
if uploaded_file is not None:
|
96 |
+
compressed_path = compress_video(uploaded_file)
|
97 |
+
st.video(compressed_path)
|
98 |
+
st.success("β
Video uploaded and compressed successfully!")
|
99 |
+
|
100 |
+
elif option == "Text":
|
101 |
+
text_input = st.text_area("Enter your text for analysis")
|
102 |
+
if text_input:
|
103 |
+
st.write("π Fake news detection processing...")
|
104 |
+
st.success("β
Text analysis completed!")
|