Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,14 +43,10 @@ def process_image(images, project_name):
|
|
| 43 |
if not images or len(images) == 0:
|
| 44 |
return "Error: Please upload at least one image to proceed.", "Pending", "", "", 0
|
| 45 |
|
| 46 |
-
# Process each image
|
| 47 |
milestones = []
|
| 48 |
for image in images:
|
| 49 |
img = Image.open(image)
|
| 50 |
|
| 51 |
-
# Debugging log for image filename
|
| 52 |
-
print(f"Processing image: {os.path.basename(image)}")
|
| 53 |
-
|
| 54 |
# Check if the image exceeds the size limit (20MB)
|
| 55 |
image_size_mb = os.path.getsize(image) / (1024 * 1024)
|
| 56 |
if image_size_mb > 20:
|
|
@@ -85,10 +81,8 @@ def process_image(images, project_name):
|
|
| 85 |
except Exception as e:
|
| 86 |
return f"Error: Failed to upload image to Salesforce - {str(e)}", "Failure", "", "", 0
|
| 87 |
|
| 88 |
-
#
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
# Check if the image represents a completed building
|
| 92 |
if "completed" in os.path.basename(image).lower() or "finished" in os.path.basename(image).lower():
|
| 93 |
milestone = "Completed" # Directly detect completion if such features exist
|
| 94 |
else:
|
|
@@ -98,14 +92,10 @@ def process_image(images, project_name):
|
|
| 98 |
milestone_index = img_hash % len(VALID_MILESTONES)
|
| 99 |
milestone = VALID_MILESTONES[milestone_index]
|
| 100 |
|
| 101 |
-
print(f"Milestone detected: {milestone}")
|
| 102 |
-
|
| 103 |
milestones.append(milestone)
|
| 104 |
|
| 105 |
# Determine overall milestone (most advanced detected)
|
| 106 |
final_milestone = max(set(milestones), key=milestones.count) if milestones else "Planning"
|
| 107 |
-
print(f"Final milestone after processing all images: {final_milestone}")
|
| 108 |
-
|
| 109 |
milestone_completion_map = {
|
| 110 |
"Planning": 10,
|
| 111 |
"Foundation": 30,
|
|
@@ -113,9 +103,7 @@ def process_image(images, project_name):
|
|
| 113 |
"Completed": 100,
|
| 114 |
}
|
| 115 |
percent_complete = milestone_completion_map.get(final_milestone, 0)
|
| 116 |
-
print(f"Completion percentage: {percent_complete}%")
|
| 117 |
|
| 118 |
-
# Completion details for different milestones
|
| 119 |
completion_details = {
|
| 120 |
"Planning": {
|
| 121 |
"completed": [
|
|
@@ -235,7 +223,6 @@ def process_image(images, project_name):
|
|
| 235 |
return result_html, "Success", final_milestone, f"{percent_complete}%"
|
| 236 |
|
| 237 |
except Exception as e:
|
| 238 |
-
print(f"Error: {str(e)}")
|
| 239 |
return f"Error: {str(e)}", "Failure", "", "", "0%"
|
| 240 |
|
| 241 |
# Gradio UI
|
|
|
|
| 43 |
if not images or len(images) == 0:
|
| 44 |
return "Error: Please upload at least one image to proceed.", "Pending", "", "", 0
|
| 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 = os.path.getsize(image) / (1024 * 1024)
|
| 52 |
if image_size_mb > 20:
|
|
|
|
| 81 |
except Exception as e:
|
| 82 |
return f"Error: Failed to upload image to Salesforce - {str(e)}", "Failure", "", "", 0
|
| 83 |
|
| 84 |
+
# Checking for external features indicating completion
|
| 85 |
+
# If image contains features suggesting a completed building (such as windows, doors, exterior finish)
|
|
|
|
|
|
|
| 86 |
if "completed" in os.path.basename(image).lower() or "finished" in os.path.basename(image).lower():
|
| 87 |
milestone = "Completed" # Directly detect completion if such features exist
|
| 88 |
else:
|
|
|
|
| 92 |
milestone_index = img_hash % len(VALID_MILESTONES)
|
| 93 |
milestone = VALID_MILESTONES[milestone_index]
|
| 94 |
|
|
|
|
|
|
|
| 95 |
milestones.append(milestone)
|
| 96 |
|
| 97 |
# Determine overall milestone (most advanced detected)
|
| 98 |
final_milestone = max(set(milestones), key=milestones.count) if milestones else "Planning"
|
|
|
|
|
|
|
| 99 |
milestone_completion_map = {
|
| 100 |
"Planning": 10,
|
| 101 |
"Foundation": 30,
|
|
|
|
| 103 |
"Completed": 100,
|
| 104 |
}
|
| 105 |
percent_complete = milestone_completion_map.get(final_milestone, 0)
|
|
|
|
| 106 |
|
|
|
|
| 107 |
completion_details = {
|
| 108 |
"Planning": {
|
| 109 |
"completed": [
|
|
|
|
| 223 |
return result_html, "Success", final_milestone, f"{percent_complete}%"
|
| 224 |
|
| 225 |
except Exception as e:
|
|
|
|
| 226 |
return f"Error: {str(e)}", "Failure", "", "", "0%"
|
| 227 |
|
| 228 |
# Gradio UI
|