PrashanthB461 commited on
Commit
5c52faa
·
verified ·
1 Parent(s): 71a216e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -6,8 +6,14 @@ import numpy as np
6
  from simple_salesforce import Salesforce
7
  import time
8
 
9
- # Salesforce connection details (replace these with your actual credentials)
10
- sf = Salesforce(username='prashanth@safetyanaluzer.com', password='SaiPrash461', security_token='MOA3BXBfGyqnjBneog8a9IcGw')
 
 
 
 
 
 
11
 
12
  try:
13
  from ultralytics import YOLO
@@ -144,8 +150,10 @@ def send_to_salesforce(violations, score, video_path):
144
  upload_date = "2025-05-08T12:00:00Z" # Replace with actual upload date
145
  status = "Reviewed" # Update based on video processing result
146
 
 
147
  # Video file upload
148
  file_id = upload_video_to_salesforce(video_path) # Upload the video and get the file ID
 
149
 
150
  # Violations details: Frame number, violation type, confidence level
151
  violations_details = "\n".join([f"Frame {v['frame']}: {v['violation']} (Confidence: {v['confidence']})" for v in violations])
@@ -164,7 +172,7 @@ def send_to_salesforce(violations, score, video_path):
164
  }
165
 
166
  try:
167
- # Insert a new record in Salesforce
168
  result = sf.Safety_Video_Reports__c.create(data)
169
  print(f"✅ Successfully created new report in Salesforce with ID: {result['id']}")
170
  except Exception as e:
@@ -174,13 +182,11 @@ def send_to_salesforce(violations, score, video_path):
174
  # Function to Upload Video to Salesforce
175
  # ==========================
176
  def upload_video_to_salesforce(video_path):
177
- # Open the video file and read it as a binary file
178
  with open(video_path, 'rb') as file:
179
  video_data = file.read()
180
 
181
- # Upload the video as a ContentVersion record in Salesforce
182
  content_version_data = {
183
- 'Title': 'Safety Video', # Title of the file
184
  'PathOnClient': 'safety_video.mp4', # Path of the file on the client's system
185
  'VersionData': video_data, # Video file content as binary
186
  'FirstPublishLocationId': 'your_salesforce_library_id', # Library ID (if required, or leave blank)
 
6
  from simple_salesforce import Salesforce
7
  import time
8
 
9
+ # Test Salesforce connection
10
+ try:
11
+ sf = Salesforce(username='prashanth@safetyanaluzer.com', password='SaiPrash461', security_token='MOA3BXBfGyqnjBneog8a9IcGw')
12
+ # Simple query to verify the connection
13
+ result = sf.query("SELECT Id FROM Safety_Video_Reports__c LIMIT 1")
14
+ print("✅ Salesforce connection successful.")
15
+ except Exception as e:
16
+ print(f"❌ Error connecting to Salesforce: {e}")
17
 
18
  try:
19
  from ultralytics import YOLO
 
150
  upload_date = "2025-05-08T12:00:00Z" # Replace with actual upload date
151
  status = "Reviewed" # Update based on video processing result
152
 
153
+ print("Starting file upload to Salesforce...")
154
  # Video file upload
155
  file_id = upload_video_to_salesforce(video_path) # Upload the video and get the file ID
156
+ print(f"File uploaded to Salesforce with ID: {file_id}")
157
 
158
  # Violations details: Frame number, violation type, confidence level
159
  violations_details = "\n".join([f"Frame {v['frame']}: {v['violation']} (Confidence: {v['confidence']})" for v in violations])
 
172
  }
173
 
174
  try:
175
+ print(f"Creating Salesforce record with data: {data}") # Log data being sent to Salesforce
176
  result = sf.Safety_Video_Reports__c.create(data)
177
  print(f"✅ Successfully created new report in Salesforce with ID: {result['id']}")
178
  except Exception as e:
 
182
  # Function to Upload Video to Salesforce
183
  # ==========================
184
  def upload_video_to_salesforce(video_path):
 
185
  with open(video_path, 'rb') as file:
186
  video_data = file.read()
187
 
 
188
  content_version_data = {
189
+ 'Title': 'Safety Video',
190
  'PathOnClient': 'safety_video.mp4', # Path of the file on the client's system
191
  'VersionData': video_data, # Video file content as binary
192
  'FirstPublishLocationId': 'your_salesforce_library_id', # Library ID (if required, or leave blank)