Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,26 +32,32 @@ except Exception as e:
|
|
| 32 |
# Valid milestones
|
| 33 |
VALID_MILESTONES = ["Foundation", "Walls Erected", "Planning", "Completed"]
|
| 34 |
|
| 35 |
-
# Updated deterministic AI prediction
|
| 36 |
def mock_ai_model(image):
|
| 37 |
img = image.convert("RGB")
|
| 38 |
max_size = 1024
|
| 39 |
img.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
| 40 |
|
| 41 |
-
#
|
| 42 |
img_bytes = img.tobytes()
|
| 43 |
img_hash = int(hashlib.sha256(img_bytes).hexdigest(), 16)
|
| 44 |
|
| 45 |
-
# Use the hash to deterministically pick milestone and percentages
|
| 46 |
milestone_index = img_hash % len(VALID_MILESTONES)
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
confidence_raw = 0.85 + ((img_hash % 1000) / 1000) * (0.95 - 0.85)
|
| 50 |
confidence_score = round(confidence_raw, 2)
|
| 51 |
|
| 52 |
-
milestone = VALID_MILESTONES[milestone_index]
|
| 53 |
-
completion_percent = completion_choices[completion_index]
|
| 54 |
-
|
| 55 |
return milestone, completion_percent, confidence_score
|
| 56 |
|
| 57 |
# Gradio function
|
|
|
|
| 32 |
# Valid milestones
|
| 33 |
VALID_MILESTONES = ["Foundation", "Walls Erected", "Planning", "Completed"]
|
| 34 |
|
| 35 |
+
# Updated deterministic AI prediction with accurate completion percentages
|
| 36 |
def mock_ai_model(image):
|
| 37 |
img = image.convert("RGB")
|
| 38 |
max_size = 1024
|
| 39 |
img.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
| 40 |
|
| 41 |
+
# Hash image bytes for deterministic output
|
| 42 |
img_bytes = img.tobytes()
|
| 43 |
img_hash = int(hashlib.sha256(img_bytes).hexdigest(), 16)
|
| 44 |
|
|
|
|
| 45 |
milestone_index = img_hash % len(VALID_MILESTONES)
|
| 46 |
+
milestone = VALID_MILESTONES[milestone_index]
|
| 47 |
+
|
| 48 |
+
# Map milestones to fixed completion percentages
|
| 49 |
+
milestone_completion_map = {
|
| 50 |
+
"Planning": 10,
|
| 51 |
+
"Foundation": 30,
|
| 52 |
+
"Walls Erected": 50,
|
| 53 |
+
"Completed": 100,
|
| 54 |
+
}
|
| 55 |
+
completion_percent = milestone_completion_map.get(milestone, 0)
|
| 56 |
+
|
| 57 |
+
# Deterministic confidence score between 0.85 and 0.95
|
| 58 |
confidence_raw = 0.85 + ((img_hash % 1000) / 1000) * (0.95 - 0.85)
|
| 59 |
confidence_score = round(confidence_raw, 2)
|
| 60 |
|
|
|
|
|
|
|
|
|
|
| 61 |
return milestone, completion_percent, confidence_score
|
| 62 |
|
| 63 |
# Gradio function
|