Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import numpy as np
|
|
| 6 |
from simple_salesforce import Salesforce
|
| 7 |
|
| 8 |
# Salesforce connection details (replace these with your actual credentials)
|
| 9 |
-
sf = Salesforce(username='
|
| 10 |
|
| 11 |
try:
|
| 12 |
from ultralytics import YOLO
|
|
@@ -101,9 +101,9 @@ def process_video(video_path, frame_skip=5):
|
|
| 101 |
|
| 102 |
video.release()
|
| 103 |
score = calculate_safety_score(violations)
|
| 104 |
-
|
| 105 |
# Send data to Salesforce
|
| 106 |
-
send_to_salesforce(violations, score)
|
| 107 |
|
| 108 |
return violations, score
|
| 109 |
|
|
@@ -126,7 +126,7 @@ def calculate_safety_score(violations):
|
|
| 126 |
base_score -= penalties.get(v["violation"], 0)
|
| 127 |
return max(base_score, 0)
|
| 128 |
|
| 129 |
-
==========================
|
| 130 |
# Send Results to Salesforce
|
| 131 |
# ==========================
|
| 132 |
def send_to_salesforce(violations, score, video_path):
|
|
@@ -138,9 +138,9 @@ def send_to_salesforce(violations, score, video_path):
|
|
| 138 |
status = "Reviewed" # Update this based on the processing state
|
| 139 |
|
| 140 |
# If you have a file or video, you can add it here as well
|
| 141 |
-
|
| 142 |
|
| 143 |
-
|
| 144 |
|
| 145 |
data = {
|
| 146 |
'Site__c': site_name, # Replace with dynamic data
|
|
|
|
| 6 |
from simple_salesforce import Salesforce
|
| 7 |
|
| 8 |
# Salesforce connection details (replace these with your actual credentials)
|
| 9 |
+
sf = Salesforce(username='your_username', password='your_password', security_token='your_security_token')
|
| 10 |
|
| 11 |
try:
|
| 12 |
from ultralytics import YOLO
|
|
|
|
| 101 |
|
| 102 |
video.release()
|
| 103 |
score = calculate_safety_score(violations)
|
| 104 |
+
|
| 105 |
# Send data to Salesforce
|
| 106 |
+
send_to_salesforce(violations, score, video_path)
|
| 107 |
|
| 108 |
return violations, score
|
| 109 |
|
|
|
|
| 126 |
base_score -= penalties.get(v["violation"], 0)
|
| 127 |
return max(base_score, 0)
|
| 128 |
|
| 129 |
+
# ==========================
|
| 130 |
# Send Results to Salesforce
|
| 131 |
# ==========================
|
| 132 |
def send_to_salesforce(violations, score, video_path):
|
|
|
|
| 138 |
status = "Reviewed" # Update this based on the processing state
|
| 139 |
|
| 140 |
# If you have a file or video, you can add it here as well
|
| 141 |
+
video_file_url = "http://path_to_video" # Replace with the actual URL or path if available
|
| 142 |
|
| 143 |
+
violations_details = "\n".join([f"Frame {v['frame']}: {v['violation']} (Confidence: {v['confidence']})" for v in violations])
|
| 144 |
|
| 145 |
data = {
|
| 146 |
'Site__c': site_name, # Replace with dynamic data
|