Update app.py
Browse files
app.py
CHANGED
@@ -51,54 +51,77 @@ import tempfile
|
|
51 |
import os
|
52 |
from PIL import Image
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
65 |
-
|
66 |
-
|
|
|
|
|
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
|
83 |
-
option = st.sidebar.radio("Select
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
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 |
-
|
94 |
-
|
95 |
-
|
|
|
96 |
compressed_path = compress_video(uploaded_file)
|
97 |
-
|
98 |
-
|
|
|
99 |
|
100 |
-
|
|
|
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!")
|
|
|
51 |
import os
|
52 |
from PIL import Image
|
53 |
|
54 |
+
st.set_page_config(page_title="Fake News & Deepfake Detection", layout="wide")
|
55 |
+
|
56 |
+
# π Image Compression Function
|
57 |
+
def compress_image(image, quality=20, max_size=(500, 500)):
|
58 |
+
img = Image.open(image).convert("RGB")
|
59 |
+
img.thumbnail(max_size) # Resize while keeping aspect ratio
|
60 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".jpg")
|
61 |
img.save(temp_file.name, "JPEG", quality=quality)
|
62 |
return temp_file.name
|
63 |
|
64 |
+
# π Video Compression Function
|
65 |
def compress_video(video):
|
66 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
|
67 |
+
|
68 |
+
# β
Save video to temporary file
|
69 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
|
70 |
+
temp_video.write(video.read())
|
71 |
+
video_path = temp_video.name
|
72 |
+
|
73 |
+
cap = cv2.VideoCapture(video_path)
|
74 |
+
|
75 |
+
if not cap.isOpened():
|
76 |
+
st.error("β Error: Unable to read video!")
|
77 |
+
return None
|
78 |
+
|
79 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
80 |
+
|
81 |
+
# β
Reduce resolution to 480p
|
82 |
+
frame_width = 640
|
83 |
+
frame_height = 480
|
84 |
out = cv2.VideoWriter(temp_file.name, fourcc, 20.0, (frame_width, frame_height))
|
85 |
+
|
86 |
while cap.isOpened():
|
87 |
ret, frame = cap.read()
|
88 |
if not ret:
|
89 |
break
|
90 |
frame = cv2.resize(frame, (frame_width, frame_height))
|
91 |
out.write(frame)
|
92 |
+
|
93 |
cap.release()
|
94 |
out.release()
|
95 |
+
|
96 |
return temp_file.name
|
97 |
|
98 |
+
# π Streamlit UI
|
99 |
st.title("π΅οΈββοΈ Fake News & Deepfake Detection Tool")
|
100 |
|
101 |
+
st.sidebar.header("π Upload Your File")
|
102 |
+
option = st.sidebar.radio("Select File Type", ["π· Image", "πΉ Video", "π Text"])
|
103 |
|
104 |
+
# π Image Upload & Compression
|
105 |
+
if option == "π· Image":
|
106 |
+
uploaded_file = st.sidebar.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
|
107 |
+
if uploaded_file:
|
108 |
compressed_path = compress_image(uploaded_file)
|
109 |
image = Image.open(compressed_path)
|
110 |
+
st.image(image, caption="πΌοΈ Compressed Image", use_column_width=True)
|
111 |
st.success("β
Image uploaded and compressed successfully!")
|
112 |
|
113 |
+
# π Video Upload & Compression
|
114 |
+
elif option == "πΉ Video":
|
115 |
+
uploaded_file = st.sidebar.file_uploader("Upload a Video", type=["mp4", "avi", "mov"])
|
116 |
+
if uploaded_file:
|
117 |
compressed_path = compress_video(uploaded_file)
|
118 |
+
if compressed_path:
|
119 |
+
st.video(compressed_path)
|
120 |
+
st.success("β
Video uploaded and compressed successfully!")
|
121 |
|
122 |
+
# π Text Input for Fake News Detection
|
123 |
+
elif option == "π Text":
|
124 |
text_input = st.text_area("Enter your text for analysis")
|
125 |
if text_input:
|
126 |
st.write("π Fake news detection processing...")
|
127 |
+
st.success("β
Text analysis completed!")
|