Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,14 @@
|
|
| 1 |
-
# All imports and env setup are the same
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
| 4 |
import os
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
from simple_salesforce import Salesforce
|
| 7 |
from datetime import datetime
|
| 8 |
-
import hashlib
|
| 9 |
import shutil
|
| 10 |
import base64
|
| 11 |
import pytz
|
| 12 |
|
| 13 |
-
# Load
|
| 14 |
load_dotenv()
|
| 15 |
SF_USERNAME = os.getenv("SF_USERNAME")
|
| 16 |
SF_PASSWORD = os.getenv("SF_PASSWORD")
|
|
@@ -70,26 +68,18 @@ def process_image(images, project_name):
|
|
| 70 |
except Exception as e:
|
| 71 |
return f"Error: Failed to upload image to Salesforce - {str(e)}", "Failure", "", "", 0
|
| 72 |
|
| 73 |
-
#
|
| 74 |
filename = os.path.basename(image).lower()
|
| 75 |
-
if "completed" in filename
|
| 76 |
milestone = "Completed"
|
| 77 |
elif "walls" in filename or "erected" in filename:
|
| 78 |
milestone = "Walls Erected"
|
| 79 |
elif "foundation" in filename:
|
| 80 |
milestone = "Foundation"
|
| 81 |
-
elif "planning" in filename
|
| 82 |
milestone = "Planning"
|
| 83 |
else:
|
| 84 |
-
|
| 85 |
-
# Optional: inspect pixel size or use hash override
|
| 86 |
-
img_hash = hashlib.sha256(img.tobytes()).hexdigest()
|
| 87 |
-
|
| 88 |
-
# If it's this known hash (from your Planning image), default it manually
|
| 89 |
-
if img_hash.startswith("f031ed44") or image_filename.endswith("QPV6O.jpg"):
|
| 90 |
-
milestone = "Planning"
|
| 91 |
-
else:
|
| 92 |
-
milestone = "Planning" # safer default instead of random logic
|
| 93 |
|
| 94 |
milestones.append(milestone)
|
| 95 |
|
|
@@ -102,7 +92,6 @@ def process_image(images, project_name):
|
|
| 102 |
}
|
| 103 |
percent_complete = milestone_completion_map.get(final_milestone, 0)
|
| 104 |
|
| 105 |
-
# --- Completion details block is unchanged (keeping original)
|
| 106 |
completion_details = {
|
| 107 |
"Planning": {
|
| 108 |
"completed": [
|
|
@@ -224,8 +213,58 @@ def process_image(images, project_name):
|
|
| 224 |
except Exception as e:
|
| 225 |
return f"Error: {str(e)}", "Failure", "", "", "0%"
|
| 226 |
|
| 227 |
-
#
|
| 228 |
-
with gr.Blocks(css="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
gr.Markdown("<h1 class='title'>Construction Progress Analyzer</h1>")
|
| 230 |
with gr.Row():
|
| 231 |
image_input = gr.Files(type="filepath", label="Upload Construction Site Photos (JPG/PNG, ≤ 20MB)")
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
import os
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
from simple_salesforce import Salesforce
|
| 6 |
from datetime import datetime
|
|
|
|
| 7 |
import shutil
|
| 8 |
import base64
|
| 9 |
import pytz
|
| 10 |
|
| 11 |
+
# Load environment variables
|
| 12 |
load_dotenv()
|
| 13 |
SF_USERNAME = os.getenv("SF_USERNAME")
|
| 14 |
SF_PASSWORD = os.getenv("SF_PASSWORD")
|
|
|
|
| 68 |
except Exception as e:
|
| 69 |
return f"Error: Failed to upload image to Salesforce - {str(e)}", "Failure", "", "", 0
|
| 70 |
|
| 71 |
+
# 👉 Milestone detection purely by filename
|
| 72 |
filename = os.path.basename(image).lower()
|
| 73 |
+
if "completed" in filename:
|
| 74 |
milestone = "Completed"
|
| 75 |
elif "walls" in filename or "erected" in filename:
|
| 76 |
milestone = "Walls Erected"
|
| 77 |
elif "foundation" in filename:
|
| 78 |
milestone = "Foundation"
|
| 79 |
+
elif "planning" in filename:
|
| 80 |
milestone = "Planning"
|
| 81 |
else:
|
| 82 |
+
milestone = "Planning" # default fallback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
milestones.append(milestone)
|
| 85 |
|
|
|
|
| 92 |
}
|
| 93 |
percent_complete = milestone_completion_map.get(final_milestone, 0)
|
| 94 |
|
|
|
|
| 95 |
completion_details = {
|
| 96 |
"Planning": {
|
| 97 |
"completed": [
|
|
|
|
| 213 |
except Exception as e:
|
| 214 |
return f"Error: {str(e)}", "Failure", "", "", "0%"
|
| 215 |
|
| 216 |
+
# UI Setup
|
| 217 |
+
with gr.Blocks(css="""
|
| 218 |
+
.gradio-container {
|
| 219 |
+
background-color: #f0f4f8;
|
| 220 |
+
font-family: Arial, sans-serif;
|
| 221 |
+
}
|
| 222 |
+
.title {
|
| 223 |
+
color: #2c3e50;
|
| 224 |
+
font-size: 24px;
|
| 225 |
+
text-align: center;
|
| 226 |
+
font-weight: bold;
|
| 227 |
+
}
|
| 228 |
+
.gradio-row {
|
| 229 |
+
text-align: center;
|
| 230 |
+
}
|
| 231 |
+
.gradio-container .output {
|
| 232 |
+
text-align: center;
|
| 233 |
+
}
|
| 234 |
+
.gradio-container .input {
|
| 235 |
+
text-align: center;
|
| 236 |
+
}
|
| 237 |
+
.gradio-container .button {
|
| 238 |
+
display: block;
|
| 239 |
+
margin: 0 auto;
|
| 240 |
+
background-color: #3498db;
|
| 241 |
+
color: white;
|
| 242 |
+
border: none;
|
| 243 |
+
padding: 10px 20px;
|
| 244 |
+
border-radius: 5px;
|
| 245 |
+
cursor: pointer;
|
| 246 |
+
}
|
| 247 |
+
.gradio-container .button:hover {
|
| 248 |
+
background-color: #2980b9;
|
| 249 |
+
}
|
| 250 |
+
progress::-webkit-progress-value {
|
| 251 |
+
background-color: #2ecc71;
|
| 252 |
+
border-radius: 5px;
|
| 253 |
+
}
|
| 254 |
+
progress::-webkit-progress-bar {
|
| 255 |
+
background-color: #ecf0f1;
|
| 256 |
+
border-radius: 5px;
|
| 257 |
+
}
|
| 258 |
+
details summary {
|
| 259 |
+
cursor: pointer;
|
| 260 |
+
padding: 10px;
|
| 261 |
+
background-color: #ecf0f1;
|
| 262 |
+
border-radius: 5px;
|
| 263 |
+
}
|
| 264 |
+
details ul {
|
| 265 |
+
margin-top: 10px;
|
| 266 |
+
}
|
| 267 |
+
""") as demo:
|
| 268 |
gr.Markdown("<h1 class='title'>Construction Progress Analyzer</h1>")
|
| 269 |
with gr.Row():
|
| 270 |
image_input = gr.Files(type="filepath", label="Upload Construction Site Photos (JPG/PNG, ≤ 20MB)")
|