Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,38 @@ from google_auth_oauthlib.flow import InstalledAppFlow
|
|
13 |
from google.auth.transport.requests import Request
|
14 |
from PIL import Image
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# === CONFIGURATION ===
|
17 |
API_KEY = "AIzaSyDojJrpauA0XZtCCDUuo9xeQHZQamYKsC4"
|
18 |
CCTVFEED_IDS = ['1KJRkSf2SKEZ1mXS9_si65IwMBtjs6p4n']
|
@@ -112,7 +144,10 @@ def detect_faces_from_video(video_path, registered_faces):
|
|
112 |
for f in faces:
|
113 |
if not any(mse(f, reg) < 200 for reg in registered_faces) and not is_duplicate(f, unique):
|
114 |
unique.append(f)
|
115 |
-
|
|
|
|
|
|
|
116 |
detected.extend(faces)
|
117 |
cap.release()
|
118 |
return detected, unique
|
|
|
13 |
from google.auth.transport.requests import Request
|
14 |
from PIL import Image
|
15 |
|
16 |
+
from simple_salesforce import Salesforce
|
17 |
+
from datetime import datetime
|
18 |
+
import uuid
|
19 |
+
|
20 |
+
# === SALESFORCE SETUP ===
|
21 |
+
sf = Salesforce(
|
22 |
+
username='[email protected]',
|
23 |
+
password='Sati@1010',
|
24 |
+
security_token='B9nS0HEyBE7YmWllqXCyiOJpY',
|
25 |
+
domain='login' # Use 'test' if you're on a sandbox
|
26 |
+
)
|
27 |
+
|
28 |
+
def log_intruder_to_salesforce(frame_id):
|
29 |
+
"""Logs a detection event to Salesforce."""
|
30 |
+
try:
|
31 |
+
sf.Hotel_Security_Alert__c.create({
|
32 |
+
'Alert_Type__c': 'Intruder',
|
33 |
+
'Detection_Timestamp__c': datetime.utcnow().isoformat(),
|
34 |
+
'HF_Detection_ID__c': f'intruder_{frame_id}_{uuid.uuid4()}',
|
35 |
+
'Confidence_Score__c': 0.90,
|
36 |
+
'Description__c': 'Detected unrecognized face from CCTV feed',
|
37 |
+
'Status__c': 'Open',
|
38 |
+
'Title__c': f'Intruder Detected Frame {frame_id}',
|
39 |
+
'Priority__c': 'Medium'
|
40 |
+
})
|
41 |
+
except Exception as e:
|
42 |
+
st.warning(f"⚠️ Failed to log to Salesforce: {e}")
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
# === CONFIGURATION ===
|
49 |
API_KEY = "AIzaSyDojJrpauA0XZtCCDUuo9xeQHZQamYKsC4"
|
50 |
CCTVFEED_IDS = ['1KJRkSf2SKEZ1mXS9_si65IwMBtjs6p4n']
|
|
|
144 |
for f in faces:
|
145 |
if not any(mse(f, reg) < 200 for reg in registered_faces) and not is_duplicate(f, unique):
|
146 |
unique.append(f)
|
147 |
+
filename = f"intruder_{frame_id}.jpg"
|
148 |
+
upload_to_drive(f, filename)
|
149 |
+
log_intruder_to_salesforce(frame_id)
|
150 |
+
|
151 |
detected.extend(faces)
|
152 |
cap.release()
|
153 |
return detected, unique
|