Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -126,35 +126,35 @@ 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):
|
| 133 |
-
# Assuming you have
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
#
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
#
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
# 'PDF_Report_URL__c': pdf_url (If you generate and store a PDF URL)
|
| 146 |
-
#}
|
| 147 |
data = {
|
| 148 |
-
'Site__c':
|
| 149 |
-
'Uploaded_By__c':
|
| 150 |
-
'Upload_Date__c':
|
| 151 |
-
'Status__c':
|
| 152 |
'Compliance_Score__c': score,
|
| 153 |
'Violations_Found__c': len(violations),
|
| 154 |
-
'Violations_Details__c':
|
|
|
|
|
|
|
|
|
|
| 155 |
}
|
| 156 |
|
| 157 |
-
|
| 158 |
try:
|
| 159 |
# Insert new record in Salesforce
|
| 160 |
result = sf.Safety_Video_Reports__c.create(data)
|
|
@@ -162,7 +162,6 @@ def send_to_salesforce(violations, score):
|
|
| 162 |
except Exception as e:
|
| 163 |
print(f"❌ Error creating/updating record in Salesforce: {e}")
|
| 164 |
|
| 165 |
-
|
| 166 |
# ==========================
|
| 167 |
# Gradio Interface
|
| 168 |
# ==========================
|
|
|
|
| 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):
|
| 133 |
+
# Assuming you have dynamic values for the Site, Uploaded_By, etc.
|
| 134 |
+
# These values can be collected from user input or a UI
|
| 135 |
+
site_name = "Sample Site" # Replace with dynamic data
|
| 136 |
+
uploaded_by = "User_1" # Replace with dynamic data (e.g., user info)
|
| 137 |
+
upload_date = "2025-05-08T12:00:00Z" # Replace with dynamic upload date
|
| 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
|
| 147 |
+
'Uploaded_By__c': uploaded_by, # Replace with actual user details
|
| 148 |
+
'Upload_Date__c': upload_date, # Replace with actual upload date
|
| 149 |
+
'Status__c': status,
|
| 150 |
'Compliance_Score__c': score,
|
| 151 |
'Violations_Found__c': len(violations),
|
| 152 |
+
'Violations_Details__c': violations_details,
|
| 153 |
+
'Video_File__c': video_file_url, # Include the file URL here if you want to store the file
|
| 154 |
+
# Optionally add a URL for the PDF report
|
| 155 |
+
# 'PDF_Report_URL__c': "http://path_to_pdf_report" # Replace with actual PDF report URL if available
|
| 156 |
}
|
| 157 |
|
|
|
|
| 158 |
try:
|
| 159 |
# Insert new record in Salesforce
|
| 160 |
result = sf.Safety_Video_Reports__c.create(data)
|
|
|
|
| 162 |
except Exception as e:
|
| 163 |
print(f"❌ Error creating/updating record in Salesforce: {e}")
|
| 164 |
|
|
|
|
| 165 |
# ==========================
|
| 166 |
# Gradio Interface
|
| 167 |
# ==========================
|