PrashanthB461 commited on
Commit
21a75a7
·
verified ·
1 Parent(s): 91f0e41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -23
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 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
  data = {
148
- 'Site__c': 'Sample Site', # You can replace with dynamic data or capture from user input
149
- 'Uploaded_By__c': 'User_1', # Example: Replace with actual user details
150
- 'Upload_Date__c': '2025-05-08T12:00:00Z', # Replace with actual upload date
151
- 'Status__c': 'Reviewed',
152
  'Compliance_Score__c': score,
153
  'Violations_Found__c': len(violations),
154
- 'Violations_Details__c': "\n".join([f"Frame {v['frame']}: {v['violation']} (Confidence: {v['confidence']})" for v in violations]),
 
 
 
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
  # ==========================