Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import torch
|
|
| 5 |
import numpy as np
|
| 6 |
from simple_salesforce import Salesforce
|
| 7 |
|
| 8 |
-
#
|
| 9 |
sf = Salesforce(username='prashanth@safetyanaluzer.com', password='SaiPrash461', security_token='MOA3BXBfGyqnjBneog8a9IcGw')
|
| 10 |
|
| 11 |
try:
|
|
@@ -101,6 +101,10 @@ def process_video(video_path, frame_skip=5):
|
|
| 101 |
|
| 102 |
video.release()
|
| 103 |
score = calculate_safety_score(violations)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
return violations, score
|
| 105 |
|
| 106 |
except Exception as e:
|
|
@@ -122,6 +126,32 @@ def calculate_safety_score(violations):
|
|
| 122 |
base_score -= penalties.get(v["violation"], 0)
|
| 123 |
return max(base_score, 0)
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
# ==========================
|
| 126 |
# Gradio Interface
|
| 127 |
# ==========================
|
|
|
|
| 5 |
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='prashanth@safetyanaluzer.com', password='SaiPrash461', security_token='MOA3BXBfGyqnjBneog8a9IcGw')
|
| 10 |
|
| 11 |
try:
|
|
|
|
| 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 |
|
| 110 |
except Exception as e:
|
|
|
|
| 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):
|
| 133 |
+
# Assuming you have the Safety_Video_Report__c record's Id, you need to get this from the user input or Salesforce
|
| 134 |
+
report_id = 'your_report_id_here'
|
| 135 |
+
|
| 136 |
+
# Prepare the data to update in Salesforce
|
| 137 |
+
violations_details = "\n".join([f"Frame {v['frame']}: {v['violation']} (Confidence: {v['confidence']})" for v in violations])
|
| 138 |
+
|
| 139 |
+
# Prepare the data payload to update Salesforce record
|
| 140 |
+
data = {
|
| 141 |
+
'Compliance_Score__c': score,
|
| 142 |
+
'Violations_Found__c': len(violations),
|
| 143 |
+
'Violations_Details__c': violations_details,
|
| 144 |
+
'Status__c': 'Reviewed', # Set to 'Reviewed' after processing
|
| 145 |
+
# 'PDF_Report_URL__c': pdf_url (If you generate and store a PDF URL)
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
try:
|
| 149 |
+
# Update the Safety_Video_Report__c record in Salesforce
|
| 150 |
+
sf.Safety_Video_Report__c.update(report_id, data)
|
| 151 |
+
print("✅ Successfully updated Salesforce with the results!")
|
| 152 |
+
except Exception as e:
|
| 153 |
+
print(f"❌ Error updating Salesforce: {e}")
|
| 154 |
+
|
| 155 |
# ==========================
|
| 156 |
# Gradio Interface
|
| 157 |
# ==========================
|