Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,21 +44,30 @@ milestone_percentage_map = {
|
|
| 44 |
# Adjust the timezone to your local timezone
|
| 45 |
local_timezone = pytz.timezone("Asia/Kolkata")
|
| 46 |
|
| 47 |
-
# AI model prediction
|
| 48 |
def mock_ai_model(image):
|
| 49 |
img = image.convert("RGB")
|
| 50 |
max_size = 1024
|
| 51 |
img.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
# Assign milestone based on hash (for simulation)
|
| 57 |
-
milestone_index = img_hash % len(milestone_percentage_map)
|
| 58 |
-
milestone = list(milestone_percentage_map.keys())[milestone_index]
|
| 59 |
completion_percent = milestone_percentage_map[milestone]
|
| 60 |
-
|
| 61 |
-
confidence_raw = 0.85 + ((img_hash % 1000) / 1000) * (0.95 - 0.85)
|
| 62 |
confidence_score = round(confidence_raw, 2)
|
| 63 |
|
| 64 |
return milestone, completion_percent, confidence_score
|
|
@@ -234,9 +243,9 @@ def process_image(image, project_name, project_type):
|
|
| 234 |
</div>
|
| 235 |
"""
|
| 236 |
|
| 237 |
-
# Create Salesforce record
|
| 238 |
now = datetime.now(local_timezone)
|
| 239 |
-
local_time = now.strftime("%Y-%m-%dT%H:%M:%S") + now.strftime("%z")[:-2] + ":" + now.strftime("%z")[-2:]
|
| 240 |
|
| 241 |
record = {
|
| 242 |
"Name__c": project_name,
|
|
|
|
| 44 |
# Adjust the timezone to your local timezone
|
| 45 |
local_timezone = pytz.timezone("Asia/Kolkata")
|
| 46 |
|
| 47 |
+
# AI model prediction with basic rule-based check
|
| 48 |
def mock_ai_model(image):
|
| 49 |
img = image.convert("RGB")
|
| 50 |
max_size = 1024
|
| 51 |
img.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
| 52 |
|
| 53 |
+
# Basic rule-based milestone detection (simplified placeholder)
|
| 54 |
+
# Check for structural elements (columns, rebar) vs. exterior features
|
| 55 |
+
img_data = list(img.getdata())
|
| 56 |
+
gray_scale = [sum(pixel) / 3 for pixel in img_data] # Simple grayscale conversion
|
| 57 |
+
avg_brightness = sum(gray_scale) / len(gray_scale)
|
| 58 |
+
|
| 59 |
+
if avg_brightness < 150: # Darker image might indicate early stages or groundwork
|
| 60 |
+
milestone = "Excavation and Foundation"
|
| 61 |
+
elif any(255 in pixel for pixel in img_data): # Bright spots might indicate concrete structures
|
| 62 |
+
milestone = "Structural Framework"
|
| 63 |
+
elif avg_brightness > 200: # Brighter image might suggest advanced stages
|
| 64 |
+
milestone = "Exterior Work"
|
| 65 |
+
else:
|
| 66 |
+
milestone_index = int(hashlib.sha256(img.tobytes()).hexdigest(), 16) % len(milestone_percentage_map)
|
| 67 |
+
milestone = list(milestone_percentage_map.keys())[milestone_index]
|
| 68 |
|
|
|
|
|
|
|
|
|
|
| 69 |
completion_percent = milestone_percentage_map[milestone]
|
| 70 |
+
confidence_raw = 0.85 + ((hashlib.sha256(img.tobytes()).hexdigest() % 1000) / 1000) * (0.95 - 0.85)
|
|
|
|
| 71 |
confidence_score = round(confidence_raw, 2)
|
| 72 |
|
| 73 |
return milestone, completion_percent, confidence_score
|
|
|
|
| 243 |
</div>
|
| 244 |
"""
|
| 245 |
|
| 246 |
+
# Create Salesforce record with current date and time
|
| 247 |
now = datetime.now(local_timezone)
|
| 248 |
+
local_time = now.strftime("%Y-%m-%dT%H:%M:%S") + now.strftime("%z")[:-2] + ":" + now.strftime("%z")[-2:] # 2025-06-30T17:07:00+05:30
|
| 249 |
|
| 250 |
record = {
|
| 251 |
"Name__c": project_name,
|