asad231 commited on
Commit
56e3c29
Β·
verified Β·
1 Parent(s): cf8aa24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -43
app.py CHANGED
@@ -1,44 +1,97 @@
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**")
 
 
 
 
 
 
 
 
 
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()