AdiKhanOfficial commited on
Commit
8435c83
·
verified ·
1 Parent(s): 44f61d1

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +15 -0
  2. nude_image_app.py +31 -0
  3. nude_video_app.py +42 -0
app.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from nude_video_app import nude_video_app
3
+ from nude_image_app import nude_image_app
4
+
5
+ st.set_page_config(page_title="Nudity Detector by Adil Khan")
6
+ def main():
7
+ app_selection = st.sidebar.radio("Select App", ("Nudity Detection Video App", "Nudity Detection Image App"))
8
+ if app_selection == "Nudity Detection Video App":
9
+ nude_video_app()
10
+ elif app_selection == "Nudity Detection Image App":
11
+ nude_image_app()
12
+
13
+
14
+ if __name__ == "__main__":
15
+ main()
nude_image_app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ from NudeDetector.NudeDetector import NudeDetector
5
+
6
+
7
+ def nude_image_app():
8
+ st.title("Image Nudity Detection App")
9
+
10
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
11
+
12
+ if uploaded_file is not None:
13
+ image = cv2.imdecode(np.fromstring(uploaded_file.read(), np.uint8), cv2.IMREAD_UNCHANGED)
14
+ detector = NudeDetector(image)
15
+
16
+ st.subheader("Nudity Detection Result:")
17
+ if detector.is_nude():
18
+ st.error("Image is Nude")
19
+ else:
20
+ st.success("Image is Safe")
21
+ col1, col2 = st.columns([1, 1])
22
+ with col1:
23
+ st.subheader("Visualized Image:")
24
+ st.image(cv2.cvtColor(detector.visualize(), cv2.COLOR_BGR2RGB), caption='Visualized Image', use_column_width=True)
25
+ with col2:
26
+ st.subheader("Nudity Blurred Image:")
27
+ st.image(cv2.cvtColor(detector.blur_nudity(), cv2.COLOR_BGR2RGB), caption='Nudity Blurred Image', use_column_width=True)
28
+
29
+
30
+ if __name__ == "__main__":
31
+ nude_image_app()
nude_video_app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import tempfile
4
+ import numpy as np
5
+ from NudeDetector.NudeDetector import NudeDetector
6
+
7
+
8
+ def nude_video_app():
9
+ st.title("Video Nudity Detection App")
10
+ uploaded_file = st.file_uploader("Upload a video", type=["mp4", "avi"])
11
+
12
+ if uploaded_file is not None:
13
+ with tempfile.NamedTemporaryFile(delete=False) as temp_file:
14
+ temp_file.write(uploaded_file.read())
15
+ uploaded_video_path = temp_file.name
16
+ cap = cv2.VideoCapture(uploaded_video_path)
17
+ skip_interval = 20
18
+ frame_index = 0
19
+ placeholder1 = st.empty()
20
+ col1, col2 = st.columns([1, 1])
21
+ with col1:
22
+ placeholder2 = st.empty()
23
+ with col2:
24
+ placeholder3 = st.empty()
25
+ while True:
26
+ success, img = cap.read()
27
+ if not success:
28
+ break
29
+ if frame_index % skip_interval == 0:
30
+ detector = NudeDetector(img)
31
+
32
+ if detector.is_nude():
33
+ placeholder1.error("Image is Nude")
34
+ else:
35
+ placeholder1.success("Image is Safe")
36
+ placeholder2.image(cv2.cvtColor(detector.visualize(), cv2.COLOR_BGR2RGB), caption='Visualized Image', use_column_width=True)
37
+ placeholder3.image(cv2.cvtColor(detector.blur_nudity(), cv2.COLOR_BGR2RGB), caption='Nudity Blurred Image', use_column_width=True)
38
+ frame_index += 1
39
+
40
+
41
+ if __name__ == "__main__":
42
+ nude_video_app()