Update app.py
Browse files
app.py
CHANGED
@@ -1,127 +1,44 @@
|
|
1 |
-
# import streamlit as st
|
2 |
-
# import numpy as np
|
3 |
-
# import cv2
|
4 |
-
# import tempfile
|
5 |
-
# import os
|
6 |
-
|
7 |
-
# # ---- Page Configuration ----
|
8 |
-
# st.set_page_config(page_title="Fake & Deepfake Detection", layout="wide")
|
9 |
-
|
10 |
-
# st.title("π° Fake News & Deepfake Detection Tool")
|
11 |
-
# st.write("π Detect Fake News, Deepfake Images, and Videos using AI")
|
12 |
-
|
13 |
-
# # ---- Fake News Detection Section ----
|
14 |
-
# st.subheader("π Fake News Detection")
|
15 |
-
# news_input = st.text_area("Enter News Text:", "Type here...")
|
16 |
-
|
17 |
-
# if st.button("Check News"):
|
18 |
-
# st.write("π Processing...")
|
19 |
-
# # Fake news detection logic (Placeholder)
|
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 |
-
# if uploaded_image is not None:
|
27 |
-
# st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
|
28 |
-
# if st.button("Analyze Image"):
|
29 |
-
# st.write("π Processing...")
|
30 |
-
# # Deepfake detection logic (Placeholder)
|
31 |
-
# st.error("β οΈ Result: This image is a Deepfake.") # Replace with model
|
32 |
-
|
33 |
-
# # ---- Deepfake Video Detection Section ----
|
34 |
-
# st.subheader("π₯ Deepfake Video Detection")
|
35 |
-
# uploaded_video = st.file_uploader("Upload a Video", type=["mp4", "avi", "mov"])
|
36 |
-
|
37 |
-
# if uploaded_video is not None:
|
38 |
-
# st.video(uploaded_video)
|
39 |
-
# if st.button("Analyze Video"):
|
40 |
-
# st.write("π Processing...")
|
41 |
-
# # Deepfake video detection logic (Placeholder)
|
42 |
-
# st.warning("β οΈ Result: This video contains Deepfake elements.") # Replace with model
|
43 |
-
|
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 |
-
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 |
-
|
|
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
frame_height = 480
|
84 |
-
out = cv2.VideoWriter(temp_file.name, fourcc, 20.0, (frame_width, frame_height))
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
break
|
90 |
-
frame = cv2.resize(frame, (frame_width, frame_height))
|
91 |
-
out.write(frame)
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
|
98 |
-
#
|
99 |
-
st.
|
|
|
100 |
|
101 |
-
|
102 |
-
|
|
|
|
|
|
|
|
|
103 |
|
104 |
-
#
|
105 |
-
|
106 |
-
|
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 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
st.video(compressed_path)
|
120 |
-
st.success("β
Video uploaded and compressed successfully!")
|
121 |
|
122 |
-
|
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!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import numpy as np
|
3 |
+
import cv2
|
4 |
import tempfile
|
5 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
# ---- Page Configuration ----
|
8 |
+
st.set_page_config(page_title="Fake & Deepfake Detection", layout="wide")
|
9 |
|
10 |
+
st.title("π° Fake News & Deepfake Detection Tool")
|
11 |
+
st.write("π Detect Fake News, Deepfake Images, and Videos using AI")
|
|
|
|
|
12 |
|
13 |
+
# ---- Fake News Detection Section ----
|
14 |
+
st.subheader("π Fake News Detection")
|
15 |
+
news_input = st.text_area("Enter News Text:", "Type here...")
|
|
|
|
|
|
|
16 |
|
17 |
+
if st.button("Check News"):
|
18 |
+
st.write("π Processing...")
|
19 |
+
# Fake news detection logic (Placeholder)
|
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 |
+
if uploaded_image is not None:
|
27 |
+
st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
|
28 |
+
if st.button("Analyze Image"):
|
29 |
+
st.write("π Processing...")
|
30 |
+
# Deepfake detection logic (Placeholder)
|
31 |
+
st.error("β οΈ Result: This image is a Deepfake.") # Replace with model
|
32 |
|
33 |
+
# ---- Deepfake Video Detection Section ----
|
34 |
+
st.subheader("π₯ Deepfake Video Detection")
|
35 |
+
uploaded_video = st.file_uploader("Upload a Video", type=["mp4", "avi", "mov"])
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
if uploaded_video is not None:
|
38 |
+
st.video(uploaded_video)
|
39 |
+
if st.button("Analyze Video"):
|
40 |
+
st.write("π Processing...")
|
41 |
+
# Deepfake video detection logic (Placeholder)
|
42 |
+
st.warning("β οΈ Result: This video contains Deepfake elements.") # Replace with model
|
|
|
|
|
43 |
|
44 |
+
st.markdown("πΉ **Developed for Fake News & Deepfake Detection Hackathon**")
|
|
|
|
|
|
|
|
|
|