Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,12 +84,30 @@ def create_pdf_report(coverage_percent, extracted_texts, annotated_image_path, o
|
|
| 84 |
|
| 85 |
def upload_image_and_get_url(image_path):
|
| 86 |
"""
|
| 87 |
-
|
| 88 |
-
|
| 89 |
"""
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
def save_record_to_salesforce(annotated_image_url, coverage_percent, original_image_pil, compliance_threshold=80):
|
| 95 |
sf = Salesforce(
|
|
|
|
| 84 |
|
| 85 |
def upload_image_and_get_url(image_path):
|
| 86 |
"""
|
| 87 |
+
Upload the image to a public directory in Hugging Face Space and return a public URL.
|
| 88 |
+
Assumes the app is hosted in a Hugging Face Space with a public /uploads folder.
|
| 89 |
"""
|
| 90 |
+
import shutil
|
| 91 |
+
import os
|
| 92 |
+
from datetime import datetime
|
| 93 |
+
import uuid
|
| 94 |
+
|
| 95 |
+
# Define the public uploads directory in the Hugging Face Space
|
| 96 |
+
public_dir = os.path.join("/home/user/app/uploads") # Adjust path based on Hugging Face Space structure
|
| 97 |
+
os.makedirs(public_dir, exist_ok=True) # Create directory if it doesn't exist
|
| 98 |
+
|
| 99 |
+
# Generate a unique filename to avoid conflicts
|
| 100 |
+
unique_filename = f"{uuid.uuid4().hex}_{datetime.utcnow().strftime('%Y%m%d_%H%M%S')}.jpg"
|
| 101 |
+
destination_path = os.path.join(public_dir, unique_filename)
|
| 102 |
+
|
| 103 |
+
# Copy the image to the public directory
|
| 104 |
+
shutil.copy(image_path, destination_path)
|
| 105 |
+
|
| 106 |
+
# Construct the public URL (adjust the base URL to match your Hugging Face Space)
|
| 107 |
+
space_url = os.environ.get('HF_SPACE_URL', 'https://your-username-your-space-name.hf.space') # Replace with your Space URL
|
| 108 |
+
public_url = f"{space_url}/uploads/{unique_filename}"
|
| 109 |
+
|
| 110 |
+
return public_url
|
| 111 |
|
| 112 |
def save_record_to_salesforce(annotated_image_url, coverage_percent, original_image_pil, compliance_threshold=80):
|
| 113 |
sf = Salesforce(
|