Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,97 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import cv2
|
4 |
-
import
|
5 |
-
|
6 |
-
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
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 gradio as gr
|
48 |
import cv2
|
49 |
+
import numpy as np
|
50 |
+
|
51 |
+
# β
Image Size Limit (MB)
|
52 |
+
MAX_IMAGE_SIZE_MB = 5 # 5MB se zyada allow nahi karega
|
53 |
+
|
54 |
+
# β
Video Size Limit (MB)
|
55 |
+
MAX_VIDEO_SIZE_MB = 20 # 20MB se zyada allow nahi karega
|
56 |
+
|
57 |
+
# β
Image Processing Function
|
58 |
+
def process_image(image):
|
59 |
+
if image is None:
|
60 |
+
return "β No image uploaded!"
|
61 |
+
|
62 |
+
# β
Image Resize (Optional: 512x512)
|
63 |
+
image = cv2.resize(image, (512, 512))
|
64 |
+
return image
|
65 |
+
|
66 |
+
# β
Video Processing Function
|
67 |
+
def process_video(video_path):
|
68 |
+
if video_path is None:
|
69 |
+
return "β No video uploaded!"
|
70 |
+
|
71 |
+
# β
Video Size Check
|
72 |
+
import os
|
73 |
+
file_size_mb = os.path.getsize(video_path) / (1024 * 1024)
|
74 |
+
if file_size_mb > MAX_VIDEO_SIZE_MB:
|
75 |
+
return f"β Video is too large! (Size: {file_size_mb:.2f}MB) - Limit: {MAX_VIDEO_SIZE_MB}MB"
|
76 |
+
|
77 |
+
return f"β
Video uploaded successfully! (Size: {file_size_mb:.2f}MB)"
|
78 |
+
|
79 |
+
# β
Gradio Interface
|
80 |
+
with gr.Blocks() as app:
|
81 |
+
gr.Markdown("## π΅οΈββοΈ Fake News & Deepfake Detection Tool")
|
82 |
+
|
83 |
+
with gr.Row():
|
84 |
+
img_input = gr.Image(type="numpy", label="πΌ Upload Image (Max: 5MB)")
|
85 |
+
img_output = gr.Image(label="π Processed Image")
|
86 |
+
img_button = gr.Button("π Detect Image")
|
87 |
+
|
88 |
+
img_button.click(process_image, inputs=img_input, outputs=img_output)
|
89 |
+
|
90 |
+
with gr.Row():
|
91 |
+
video_input = gr.File(label="π₯ Upload Video (Max: 20MB)", file_types=[".mp4"])
|
92 |
+
video_output = gr.Textbox(label="π Video Status")
|
93 |
+
video_button = gr.Button("π Detect Video")
|
94 |
+
|
95 |
+
video_button.click(process_video, inputs=video_input, outputs=video_output)
|
96 |
+
|
97 |
+
app.launch()
|