siddhantuniyal commited on
Commit
8768717
·
verified ·
1 Parent(s): 7618594

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +58 -0
  2. requirements.txt +53 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_client import Client , handle_file
3
+ import cv2
4
+ import os
5
+ from PIL import Image
6
+
7
+ clientImgPipeLn = Client("dj-dawgs-ipd/IPD_IMAGE_PIPELINE")
8
+
9
+ def predict(video_path):
10
+ cap = cv2.VideoCapture(video_path)
11
+ fps = int(cap.get(cv2.CAP_PROP_FPS))
12
+ frame_interval = fps * 2
13
+
14
+ frame_count = 0
15
+ success = True
16
+
17
+ temp_dir = "temp_frames"
18
+ os.makedirs(temp_dir, exist_ok=True)
19
+
20
+ res = 'not_hate'
21
+
22
+ while success:
23
+ success, frame = cap.read()
24
+ if frame_count % frame_interval == 0 and success:
25
+ temp_image_path = os.path.join(temp_dir, f"frame_{frame_count // fps}s.jpg")
26
+ cv2.imwrite(temp_image_path, frame)
27
+
28
+ response = clientImgPipeLn.predict(
29
+ image=handle_file(temp_image_path),
30
+ api_name="/predict"
31
+ )
32
+ print(f"Response for frame at {frame_count // fps}s: {response}")
33
+ if(response[0]['label'] == 'hate'):
34
+ res = 'hate'
35
+ break
36
+
37
+ frame_count += 1
38
+
39
+ cap.release()
40
+
41
+ for file in os.listdir(temp_dir):
42
+ os.remove(os.path.join(temp_dir, file))
43
+ os.rmdir(temp_dir)
44
+
45
+ print("prediction successful")
46
+
47
+ return res
48
+
49
+ iface = gr.Interface(fn=predict,
50
+ inputs = gr.Video(),
51
+ outputs=[gr.Label(label = "Class")],
52
+ title = "Hate Speech Detection in Video",
53
+ description = "Detect hateful symbols or text in Video"
54
+ )
55
+
56
+ if __name__ == "__main__":
57
+ iface.launch()
58
+
requirements.txt ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ annotated-types==0.7.0
3
+ anyio==4.7.0
4
+ certifi==2024.12.14
5
+ charset-normalizer==3.4.1
6
+ click==8.1.8
7
+ colorama==0.4.6
8
+ fastapi==0.115.6
9
+ ffmpy==0.5.0
10
+ filelock==3.16.1
11
+ fsspec==2024.12.0
12
+ gradio==5.9.1
13
+ gradio_client==1.5.2
14
+ h11==0.14.0
15
+ httpcore==1.0.7
16
+ httpx==0.28.1
17
+ huggingface-hub==0.27.0
18
+ idna==3.10
19
+ Jinja2==3.1.5
20
+ markdown-it-py==3.0.0
21
+ MarkupSafe==2.1.5
22
+ mdurl==0.1.2
23
+ numpy==2.2.1
24
+ opencv-python==4.10.0.84
25
+ orjson==3.10.12
26
+ packaging==24.2
27
+ pandas==2.2.3
28
+ pillow==11.0.0
29
+ pydantic==2.10.4
30
+ pydantic_core==2.27.2
31
+ pydub==0.25.1
32
+ Pygments==2.18.0
33
+ python-dateutil==2.9.0.post0
34
+ python-multipart==0.0.20
35
+ pytz==2024.2
36
+ PyYAML==6.0.2
37
+ requests==2.32.3
38
+ rich==13.9.4
39
+ ruff==0.8.4
40
+ safehttpx==0.1.6
41
+ semantic-version==2.10.0
42
+ shellingham==1.5.4
43
+ six==1.17.0
44
+ sniffio==1.3.1
45
+ starlette==0.41.3
46
+ tomlkit==0.13.2
47
+ tqdm==4.67.1
48
+ typer==0.15.1
49
+ typing_extensions==4.12.2
50
+ tzdata==2024.2
51
+ urllib3==2.3.0
52
+ uvicorn==0.34.0
53
+ websockets==14.1