asad231 commited on
Commit
97e3cb7
Β·
verified Β·
1 Parent(s): 51b55ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -114
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
- 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!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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**")