Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .gradio/certificate.pem +31 -0
- README.md +3 -9
- requirements.txt +3 -0
- vision.py +68 -0
.gradio/certificate.pem
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-----BEGIN CERTIFICATE-----
|
2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
11 |
+
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
|
12 |
+
B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukm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3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
31 |
+
-----END CERTIFICATE-----
|
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: gray
|
5 |
-
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: CCTV_Analysis
|
3 |
+
app_file: vision.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
+
sdk_version: 3.37.0
|
|
|
|
|
6 |
---
|
|
|
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
opencv-python
|
2 |
+
openai
|
3 |
+
gradio
|
vision.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import base64
|
3 |
+
import os
|
4 |
+
from openai import OpenAI
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
8 |
+
|
9 |
+
# Add this list of common video file extensions
|
10 |
+
ALLOWED_EXTENSIONS = ['.mp4', '.avi', '.mov', '.mkv', '.wmv', '.flv', '.webm']
|
11 |
+
|
12 |
+
def process_video(video_path):
|
13 |
+
if video_path is None:
|
14 |
+
return "Please upload a video file."
|
15 |
+
|
16 |
+
# Check if the file extension is in the allowed list
|
17 |
+
_, file_extension = os.path.splitext(video_path)
|
18 |
+
if file_extension.lower() not in ALLOWED_EXTENSIONS:
|
19 |
+
return f"Invalid file type. Allowed formats are: {', '.join(ALLOWED_EXTENSIONS)}"
|
20 |
+
|
21 |
+
# Check if the input is a valid video file
|
22 |
+
video = cv2.VideoCapture(video_path)
|
23 |
+
if not video.isOpened():
|
24 |
+
return "Invalid input. Please upload a valid video file."
|
25 |
+
|
26 |
+
fps = video.get(cv2.CAP_PROP_FPS)
|
27 |
+
max_frames = int(15 * fps) # Limit to 15 seconds
|
28 |
+
|
29 |
+
base64Frames = []
|
30 |
+
frame_count = 0
|
31 |
+
while video.isOpened() and frame_count < max_frames:
|
32 |
+
success, frame = video.read()
|
33 |
+
if not success:
|
34 |
+
break
|
35 |
+
_, buffer = cv2.imencode(".jpg", frame)
|
36 |
+
base64Frames.append(base64.b64encode(buffer).decode("utf-8"))
|
37 |
+
frame_count += 1
|
38 |
+
|
39 |
+
video.release()
|
40 |
+
|
41 |
+
PROMPT_MESSAGES = [
|
42 |
+
{
|
43 |
+
"role": "user",
|
44 |
+
"content": [
|
45 |
+
"These are frames from a video. Do sentiment analysis in accordance with all kind of cctv detection. Sentiment can be defined as normal, fight, criminal activity, shoplifting, burglary, animal fighting, animal cruelty, weapon detection, abandoned bags detection, crowd detection, fire detection, loitering detection. Return only the sentiment within a few words. Sentiment could be a combination of all the sentiments. If it doesn't match any of the sentiment then return what you think is the right sentiment.",
|
46 |
+
*map(lambda x: {"image": x, "resize": 768}, base64Frames[0::25]),
|
47 |
+
],
|
48 |
+
},
|
49 |
+
]
|
50 |
+
|
51 |
+
params = {
|
52 |
+
"model": "gpt-4o",
|
53 |
+
"messages": PROMPT_MESSAGES,
|
54 |
+
"max_tokens": 100,
|
55 |
+
}
|
56 |
+
|
57 |
+
result = client.chat.completions.create(**params)
|
58 |
+
return result.choices[0].message.content
|
59 |
+
|
60 |
+
iface = gr.Interface(
|
61 |
+
fn=process_video,
|
62 |
+
inputs=gr.Video(label="Upload a video (max 15 seconds)"),
|
63 |
+
outputs="text",
|
64 |
+
title="CCTV Video Analysis",
|
65 |
+
description=f"Upload a video (max 15 seconds) to analyze its sentiment. Allowed formats: {', '.join(ALLOWED_EXTENSIONS)}. Images are not accepted.",
|
66 |
+
)
|
67 |
+
|
68 |
+
iface.launch(share=True)
|