Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ import shutil
|
|
| 9 |
import base64
|
| 10 |
import pytz
|
| 11 |
import time
|
|
|
|
| 12 |
|
| 13 |
# Load environment variables
|
| 14 |
print("Loading environment variables at", datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S IST"))
|
|
@@ -51,16 +52,35 @@ milestone_percentage_map = {
|
|
| 51 |
# Adjust the timezone to your local timezone
|
| 52 |
local_timezone = pytz.timezone("Asia/Kolkata")
|
| 53 |
|
| 54 |
-
# Enhanced AI model prediction with heuristic for completion
|
| 55 |
def mock_ai_model(image):
|
| 56 |
img = image.convert("RGB")
|
| 57 |
max_size = 1024
|
| 58 |
img.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
| 59 |
|
| 60 |
-
#
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
return "Final Completion", 100, 0.95
|
| 65 |
|
| 66 |
# Fallback to hash-based simulation
|
|
|
|
| 9 |
import base64
|
| 10 |
import pytz
|
| 11 |
import time
|
| 12 |
+
from PIL import ImageEnhance
|
| 13 |
|
| 14 |
# Load environment variables
|
| 15 |
print("Loading environment variables at", datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S IST"))
|
|
|
|
| 52 |
# Adjust the timezone to your local timezone
|
| 53 |
local_timezone = pytz.timezone("Asia/Kolkata")
|
| 54 |
|
| 55 |
+
# Enhanced AI model prediction with stricter heuristic for completion
|
| 56 |
def mock_ai_model(image):
|
| 57 |
img = image.convert("RGB")
|
| 58 |
max_size = 1024
|
| 59 |
img.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
| 60 |
|
| 61 |
+
# Enhance contrast to detect features
|
| 62 |
+
enhancer = ImageEnhance.Contrast(img)
|
| 63 |
+
img_enhanced = enhancer.enhance(2.0)
|
| 64 |
+
|
| 65 |
+
# Stricter heuristic for Final Completion (100%)
|
| 66 |
+
img_data = list(img_enhanced.getdata())
|
| 67 |
+
total_pixels = len(img_data)
|
| 68 |
+
brightness_avg = sum(sum(pixel) / 3 for pixel in img_data) / total_pixels
|
| 69 |
+
color_variation = max(max(pixel) - min(pixel) for pixel in img_data)
|
| 70 |
+
|
| 71 |
+
# Edge detection (simple count of significant color changes)
|
| 72 |
+
edge_count = 0
|
| 73 |
+
width, height = img_enhanced.size
|
| 74 |
+
for x in range(width - 1):
|
| 75 |
+
for y in range(height - 1):
|
| 76 |
+
r, g, b = img_enhanced.getpixel((x, y))
|
| 77 |
+
r_next, g_next, b_next = img_enhanced.getpixel((x + 1, y + 1))
|
| 78 |
+
if abs(r - r_next) > 50 or abs(g - g_next) > 50 or abs(b - b_next) > 50:
|
| 79 |
+
edge_count += 1
|
| 80 |
+
edge_ratio = edge_count / (width * height)
|
| 81 |
+
|
| 82 |
+
# Final Completion criteria: high brightness, low variation, low edges (finished look)
|
| 83 |
+
if brightness_avg > 220 and color_variation < 15 and edge_ratio < 0.05:
|
| 84 |
return "Final Completion", 100, 0.95
|
| 85 |
|
| 86 |
# Fallback to hash-based simulation
|