Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,8 +22,8 @@ MODEL_PATH = os.getenv("SAFETY_MODEL_PATH", DEFAULT_MODEL_PATH)
|
|
| 22 |
STATIC_OUTPUT_DIR = "static/output"
|
| 23 |
os.makedirs(STATIC_OUTPUT_DIR, exist_ok=True)
|
| 24 |
|
| 25 |
-
# Base URL for publicly accessible files (
|
| 26 |
-
BASE_PUBLIC_URL = "https://huggingface.co/spaces/PrashanthB461/AI_Safety_Demo1/
|
| 27 |
|
| 28 |
VIOLATION_LABELS = {
|
| 29 |
0: "no_helmet",
|
|
@@ -163,6 +163,10 @@ def generate_pdf_report(violations, snapshots, score):
|
|
| 163 |
c.save()
|
| 164 |
print(f"PDF generated at {pdf_path}")
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
# Generate public URL for the PDF
|
| 167 |
pdf_url = f"{BASE_PUBLIC_URL}{pdf_filename}"
|
| 168 |
print(f"Public PDF URL: {pdf_url}")
|
|
@@ -251,7 +255,8 @@ def process_video(video_data, frame_skip=5, max_frames=100):
|
|
| 251 |
|
| 252 |
# Create Salesforce record with the PDF URL
|
| 253 |
record_id = push_report_to_salesforce(score, violations, pdf_url)
|
| 254 |
-
|
|
|
|
| 255 |
|
| 256 |
with open(pdf_path, "rb") as f:
|
| 257 |
pdf_base64 = base64.b64encode(f.read()).decode('utf-8')
|
|
|
|
| 22 |
STATIC_OUTPUT_DIR = "static/output"
|
| 23 |
os.makedirs(STATIC_OUTPUT_DIR, exist_ok=True)
|
| 24 |
|
| 25 |
+
# Base URL for publicly accessible files (Hugging Face Spaces)
|
| 26 |
+
BASE_PUBLIC_URL = "https://huggingface.co/spaces/PrashanthB461/AI_Safety_Demo1/raw/main/static/output/"
|
| 27 |
|
| 28 |
VIOLATION_LABELS = {
|
| 29 |
0: "no_helmet",
|
|
|
|
| 163 |
c.save()
|
| 164 |
print(f"PDF generated at {pdf_path}")
|
| 165 |
|
| 166 |
+
# Verify the file exists
|
| 167 |
+
if not os.path.exists(pdf_path):
|
| 168 |
+
raise Exception(f"PDF file not found at {pdf_path}")
|
| 169 |
+
|
| 170 |
# Generate public URL for the PDF
|
| 171 |
pdf_url = f"{BASE_PUBLIC_URL}{pdf_filename}"
|
| 172 |
print(f"Public PDF URL: {pdf_url}")
|
|
|
|
| 255 |
|
| 256 |
# Create Salesforce record with the PDF URL
|
| 257 |
record_id = push_report_to_salesforce(score, violations, pdf_url)
|
| 258 |
+
if not record_id:
|
| 259 |
+
print("⚠️ Salesforce record creation failed, but PDF URL is available")
|
| 260 |
|
| 261 |
with open(pdf_path, "rb") as f:
|
| 262 |
pdf_base64 = base64.b64encode(f.read()).decode('utf-8')
|