Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,23 +45,22 @@ def process_image(images, project_name):
|
|
| 45 |
|
| 46 |
milestones = []
|
| 47 |
for image in images:
|
| 48 |
-
img = Image.open(image
|
| 49 |
|
| 50 |
# Check if the image exceeds the size limit (20MB)
|
| 51 |
-
image_size_mb = len(image
|
| 52 |
if image_size_mb > 20:
|
| 53 |
return "Error: One or more images exceed 20MB.", "Failure", "", "", 0
|
| 54 |
-
if not str(image
|
| 55 |
return "Error: Only JPG/PNG images are supported.", "Failure", "", "", 0
|
| 56 |
|
| 57 |
# Convert image to base64 before uploading to Salesforce
|
| 58 |
-
|
| 59 |
-
image_data = base64.b64encode(image_file.read()).decode('utf-8')
|
| 60 |
|
| 61 |
# Create the ContentVersion record in Salesforce
|
| 62 |
content_version = {
|
| 63 |
-
'Title': image
|
| 64 |
-
'PathOnClient':
|
| 65 |
'VersionData': image_data
|
| 66 |
}
|
| 67 |
|
|
@@ -74,7 +73,7 @@ def process_image(images, project_name):
|
|
| 74 |
return f"Error: Failed to upload image to Salesforce - {str(e)}", "Failure", "", "", 0
|
| 75 |
|
| 76 |
# Enhanced Milestone Detection
|
| 77 |
-
milestone = detect_milestone(
|
| 78 |
|
| 79 |
milestones.append(milestone)
|
| 80 |
|
|
@@ -230,7 +229,7 @@ with gr.Blocks(css="""
|
|
| 230 |
""") as demo:
|
| 231 |
gr.Markdown("<h1 class='title'>Construction Progress Analyzer</h1>")
|
| 232 |
with gr.Row():
|
| 233 |
-
image_input = gr.Files(type="
|
| 234 |
project_name_input = gr.Textbox(label="Project Name (Required)", placeholder="e.g. Project_12345")
|
| 235 |
|
| 236 |
submit_button = gr.Button("Process Images")
|
|
|
|
| 45 |
|
| 46 |
milestones = []
|
| 47 |
for image in images:
|
| 48 |
+
img = Image.open(image) # Open the image directly from binary data
|
| 49 |
|
| 50 |
# Check if the image exceeds the size limit (20MB)
|
| 51 |
+
image_size_mb = len(image) / (1024 * 1024)
|
| 52 |
if image_size_mb > 20:
|
| 53 |
return "Error: One or more images exceed 20MB.", "Failure", "", "", 0
|
| 54 |
+
if not str(image).lower().endswith(('.jpg', '.jpeg', '.png')):
|
| 55 |
return "Error: Only JPG/PNG images are supported.", "Failure", "", "", 0
|
| 56 |
|
| 57 |
# Convert image to base64 before uploading to Salesforce
|
| 58 |
+
image_data = base64.b64encode(image).decode('utf-8')
|
|
|
|
| 59 |
|
| 60 |
# Create the ContentVersion record in Salesforce
|
| 61 |
content_version = {
|
| 62 |
+
'Title': project_name, # Assuming project name or a unique image title
|
| 63 |
+
'PathOnClient': project_name, # Same here for simplicity
|
| 64 |
'VersionData': image_data
|
| 65 |
}
|
| 66 |
|
|
|
|
| 73 |
return f"Error: Failed to upload image to Salesforce - {str(e)}", "Failure", "", "", 0
|
| 74 |
|
| 75 |
# Enhanced Milestone Detection
|
| 76 |
+
milestone = detect_milestone(project_name)
|
| 77 |
|
| 78 |
milestones.append(milestone)
|
| 79 |
|
|
|
|
| 229 |
""") as demo:
|
| 230 |
gr.Markdown("<h1 class='title'>Construction Progress Analyzer</h1>")
|
| 231 |
with gr.Row():
|
| 232 |
+
image_input = gr.Files(type="binary", label="Upload Construction Site Photos (JPG/PNG, ≤ 20MB)") # Use 'binary' to handle image data
|
| 233 |
project_name_input = gr.Textbox(label="Project Name (Required)", placeholder="e.g. Project_12345")
|
| 234 |
|
| 235 |
submit_button = gr.Button("Process Images")
|