Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,7 +24,7 @@ try:
|
|
| 24 |
username=SF_USERNAME,
|
| 25 |
password=SF_PASSWORD,
|
| 26 |
security_token=SF_SECURITY_TOKEN,
|
| 27 |
-
domain='login'
|
| 28 |
)
|
| 29 |
except Exception as e:
|
| 30 |
print(f"Salesforce connection failed: {str(e)}")
|
|
@@ -68,12 +68,19 @@ def process_image(images, project_name):
|
|
| 68 |
# Process each image
|
| 69 |
detected_elements_all = []
|
| 70 |
for image in images:
|
| 71 |
-
img =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
image_size_mb = os.path.getsize(image) / (1024 * 1024)
|
| 73 |
if image_size_mb > 20:
|
| 74 |
return "Error: One or more images exceed 20MB.", "Failure", "", "", 0
|
| 75 |
-
if not str(image).lower().endswith(('.jpg', '.jpeg', '.png')):
|
| 76 |
-
return "Error: Only JPG
|
| 77 |
|
| 78 |
# Save image to public folder temporarily before uploading to Salesforce
|
| 79 |
upload_dir = "public_uploads"
|
|
|
|
| 24 |
username=SF_USERNAME,
|
| 25 |
password=SF_PASSWORD,
|
| 26 |
security_token=SF_SECURITY_TOKEN,
|
| 27 |
+
domain='login'
|
| 28 |
)
|
| 29 |
except Exception as e:
|
| 30 |
print(f"Salesforce connection failed: {str(e)}")
|
|
|
|
| 68 |
# Process each image
|
| 69 |
detected_elements_all = []
|
| 70 |
for image in images:
|
| 71 |
+
img = None
|
| 72 |
+
try:
|
| 73 |
+
img = Image.open(image)
|
| 74 |
+
except Exception as e:
|
| 75 |
+
if "cannot identify image file" in str(e):
|
| 76 |
+
return f"Error: Unsupported image format '{os.path.basename(image)}'. Please use JPG, JPEG, PNG, or convert to a supported format.", "Failure", "", "", 0
|
| 77 |
+
return f"Error: Failed to open image '{os.path.basename(image)}' - {str(e)}", "Failure", "", "", 0
|
| 78 |
+
|
| 79 |
image_size_mb = os.path.getsize(image) / (1024 * 1024)
|
| 80 |
if image_size_mb > 20:
|
| 81 |
return "Error: One or more images exceed 20MB.", "Failure", "", "", 0
|
| 82 |
+
if not str(image).lower().endswith(('.jpg', '.jpeg', '.png', '.avif')): # Updated to include .avif
|
| 83 |
+
return "Error: Only JPG, JPEG, PNG, or AVIF images are supported.", "Failure", "", "", 0
|
| 84 |
|
| 85 |
# Save image to public folder temporarily before uploading to Salesforce
|
| 86 |
upload_dir = "public_uploads"
|