Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,7 +35,7 @@ CONFIG = {
|
|
| 35 |
},
|
| 36 |
"PUBLIC_URL_BASE": "https://huggingface.co/spaces/PrashanthB461/AI_Safety_Demo1/resolve/main/static/output/",
|
| 37 |
"FRAME_SKIP": 5,
|
| 38 |
-
"MAX_PROCESSING_TIME":
|
| 39 |
}
|
| 40 |
|
| 41 |
# Setup logging
|
|
@@ -169,26 +169,28 @@ def push_report_to_salesforce(violations, score, pdf_path, pdf_file):
|
|
| 169 |
"Status__c": "Pending",
|
| 170 |
"PDF_Report_URL__c": pdf_url
|
| 171 |
}
|
| 172 |
-
logger.debug(f"
|
| 173 |
try:
|
| 174 |
record = sf.Safety_Video_Report__c.create(record_data)
|
|
|
|
| 175 |
except Exception as e:
|
| 176 |
logger.error(f"Failed to create Safety_Video_Report__c: {e}")
|
|
|
|
| 177 |
record = sf.Account.create({"Name": f"Safety_Report_{int(time.time())}"})
|
| 178 |
-
logger.warning(f"Fell back to creating Account record: {record}")
|
| 179 |
record_id = record["id"]
|
| 180 |
-
logger.info(f"Salesforce record created: {record_id}")
|
| 181 |
|
| 182 |
if pdf_file:
|
| 183 |
-
uploaded_url = upload_pdf_to_salesforce(sf, pdf_file,
|
| 184 |
if uploaded_url:
|
| 185 |
try:
|
| 186 |
sf.Safety_Video_Report__c.update(record_id, {"PDF_Report_URL__c": uploaded_url})
|
|
|
|
| 187 |
except Exception as e:
|
| 188 |
logger.error(f"Failed to update Safety_Video_Report__c: {e}")
|
| 189 |
sf.Account.update(record_id, {"Description": uploaded_url})
|
|
|
|
| 190 |
pdf_url = uploaded_url
|
| 191 |
-
logger.debug(f"Updated record {record_id} with PDF URL: {pdf_url}")
|
| 192 |
|
| 193 |
return record_id, pdf_url
|
| 194 |
except Exception as e:
|
|
@@ -226,7 +228,6 @@ def process_video(video_data):
|
|
| 226 |
|
| 227 |
violations, snapshots = [], []
|
| 228 |
frame_count = 0
|
| 229 |
-
start_time = time.time()
|
| 230 |
fps = video.get(cv2.CAP_PROP_FPS)
|
| 231 |
max_frames = int(CONFIG["MAX_PROCESSING_TIME"] * fps)
|
| 232 |
|
|
|
|
| 35 |
},
|
| 36 |
"PUBLIC_URL_BASE": "https://huggingface.co/spaces/PrashanthB461/AI_Safety_Demo1/resolve/main/static/output/",
|
| 37 |
"FRAME_SKIP": 5,
|
| 38 |
+
"MAX_PROCESSING_TIME": 60 # Updated to 60 seconds
|
| 39 |
}
|
| 40 |
|
| 41 |
# Setup logging
|
|
|
|
| 169 |
"Status__c": "Pending",
|
| 170 |
"PDF_Report_URL__c": pdf_url
|
| 171 |
}
|
| 172 |
+
logger.debug(f"Attempting to create Salesforce record with data: {record_data}")
|
| 173 |
try:
|
| 174 |
record = sf.Safety_Video_Report__c.create(record_data)
|
| 175 |
+
logger.info(f"Successfully created Safety_Video_Report__c record: {record['id']}")
|
| 176 |
except Exception as e:
|
| 177 |
logger.error(f"Failed to create Safety_Video_Report__c: {e}")
|
| 178 |
+
# Fallback to Account object
|
| 179 |
record = sf.Account.create({"Name": f"Safety_Report_{int(time.time())}"})
|
| 180 |
+
logger.warning(f"Fell back to creating Account record: {record['id']}")
|
| 181 |
record_id = record["id"]
|
|
|
|
| 182 |
|
| 183 |
if pdf_file:
|
| 184 |
+
uploaded_url = upload_pdf_to_salesforce(sf, pdf_file, record_id)
|
| 185 |
if uploaded_url:
|
| 186 |
try:
|
| 187 |
sf.Safety_Video_Report__c.update(record_id, {"PDF_Report_URL__c": uploaded_url})
|
| 188 |
+
logger.debug(f"Updated Safety_Video_Report__c record {record_id} with PDF URL: {uploaded_url}")
|
| 189 |
except Exception as e:
|
| 190 |
logger.error(f"Failed to update Safety_Video_Report__c: {e}")
|
| 191 |
sf.Account.update(record_id, {"Description": uploaded_url})
|
| 192 |
+
logger.debug(f"Updated Account record {record_id} with PDF URL: {uploaded_url}")
|
| 193 |
pdf_url = uploaded_url
|
|
|
|
| 194 |
|
| 195 |
return record_id, pdf_url
|
| 196 |
except Exception as e:
|
|
|
|
| 228 |
|
| 229 |
violations, snapshots = [], []
|
| 230 |
frame_count = 0
|
|
|
|
| 231 |
fps = video.get(cv2.CAP_PROP_FPS)
|
| 232 |
max_frames = int(CONFIG["MAX_PROCESSING_TIME"] * fps)
|
| 233 |
|