Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from simple_salesforce import Salesforce
|
|
| 6 |
from datetime import datetime
|
| 7 |
import hashlib
|
| 8 |
import shutil
|
|
|
|
| 9 |
|
| 10 |
# Load environment variables
|
| 11 |
load_dotenv()
|
|
@@ -78,16 +79,19 @@ def process_image(image, project_name):
|
|
| 78 |
saved_image_path = os.path.join(upload_dir, image_filename)
|
| 79 |
shutil.copy(image, saved_image_path)
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
# Upload to Salesforce as a ContentVersion
|
| 82 |
try:
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
content_version = sf.ContentVersion.create(content_version_data)
|
| 91 |
|
| 92 |
# Generate download URL for the uploaded image
|
| 93 |
file_url = f"https://{sf.sf_instance}/sfc/servlet.shepherd/version/download/{content_version['id']}"
|
|
@@ -144,4 +148,4 @@ with gr.Blocks(css=".gradio-container {background-color: #f0f4f8; font-family: A
|
|
| 144 |
outputs=[output_text, upload_status, milestone, confidence, progress]
|
| 145 |
)
|
| 146 |
|
| 147 |
-
demo.launch(share=
|
|
|
|
| 6 |
from datetime import datetime
|
| 7 |
import hashlib
|
| 8 |
import shutil
|
| 9 |
+
import base64
|
| 10 |
|
| 11 |
# Load environment variables
|
| 12 |
load_dotenv()
|
|
|
|
| 79 |
saved_image_path = os.path.join(upload_dir, image_filename)
|
| 80 |
shutil.copy(image, saved_image_path)
|
| 81 |
|
| 82 |
+
# Open the image file and encode it as base64
|
| 83 |
+
with open(saved_image_path, "rb") as file:
|
| 84 |
+
encoded_image = base64.b64encode(file.read()).decode('utf-8')
|
| 85 |
+
|
| 86 |
# Upload to Salesforce as a ContentVersion
|
| 87 |
try:
|
| 88 |
+
content_version_data = {
|
| 89 |
+
'Title': image_filename,
|
| 90 |
+
'PathOnClient': image_filename,
|
| 91 |
+
'VersionData': encoded_image, # Using the base64-encoded image data
|
| 92 |
+
'FirstPublishLocationId': 'your_sobject_id', # Replace with the appropriate Salesforce object ID (e.g., Project or Construction)
|
| 93 |
+
}
|
| 94 |
+
content_version = sf.ContentVersion.create(content_version_data)
|
|
|
|
| 95 |
|
| 96 |
# Generate download URL for the uploaded image
|
| 97 |
file_url = f"https://{sf.sf_instance}/sfc/servlet.shepherd/version/download/{content_version['id']}"
|
|
|
|
| 148 |
outputs=[output_text, upload_status, milestone, confidence, progress]
|
| 149 |
)
|
| 150 |
|
| 151 |
+
demo.launch(share=True)
|