Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -88,11 +88,10 @@ def process_image(images, project_name):
|
|
| 88 |
|
| 89 |
# Adjust milestone detection based on internal/external features
|
| 90 |
if milestone == "Walls Erected" and any("interior" in img_text.lower() for img_text in [os.path.basename(image)] if img_text):
|
| 91 |
-
# Check for visible internal works like electrical/plumbing
|
| 92 |
if any(keyword in str(os.path.basename(image)).lower() for keyword in ["electrical", "plumbing", "wiring", "pipes"]):
|
| 93 |
-
milestone = "Completed"
|
| 94 |
else:
|
| 95 |
-
milestone = "Walls Erected"
|
| 96 |
|
| 97 |
milestones.append(milestone)
|
| 98 |
|
|
@@ -106,7 +105,6 @@ def process_image(images, project_name):
|
|
| 106 |
}
|
| 107 |
percent_complete = milestone_completion_map.get(final_milestone, 0)
|
| 108 |
|
| 109 |
-
# Detailed Completion Breakdown based on final milestone
|
| 110 |
completion_details = {
|
| 111 |
"Planning": {
|
| 112 |
"completed": [
|
|
@@ -166,7 +164,6 @@ def process_image(images, project_name):
|
|
| 166 |
completed_html = "".join([f'<li style="color: green;">✔ {task}</li>' for task in completed_tasks])
|
| 167 |
not_completed_html = "".join([f'<li style="color: red;">✘ {task}</li>' for task in not_completed_tasks])
|
| 168 |
|
| 169 |
-
# Create HTML for the output with collapsible sections and progress bar
|
| 170 |
result_html = f"""
|
| 171 |
<div style="font-family: Arial, sans-serif; padding: 20px; background-color: #f9f9f9; border-radius: 10px;">
|
| 172 |
<h2 style="color: #2c3e50; text-align: center;">Project Summary</h2>
|
|
@@ -206,11 +203,9 @@ def process_image(images, project_name):
|
|
| 206 |
</div>
|
| 207 |
"""
|
| 208 |
|
| 209 |
-
# Adjust the current time to local timezone with proper ISO 8601 format
|
| 210 |
now = datetime.now(local_timezone)
|
| 211 |
local_time = now.strftime("%Y-%m-%dT%H:%M:%S") + now.strftime("%z")[:-2] + ":" + now.strftime("%z")[-2:]
|
| 212 |
|
| 213 |
-
# Create the Salesforce record (removing confidence score)
|
| 214 |
record = {
|
| 215 |
"Name__c": project_name,
|
| 216 |
"Current_Milestone__c": final_milestone,
|
|
@@ -226,12 +221,12 @@ def process_image(images, project_name):
|
|
| 226 |
except Exception as e:
|
| 227 |
return f"Error: Failed to update Salesforce - {str(e)}", "Failure", "", "", 0
|
| 228 |
|
| 229 |
-
return result_html, "Success", final_milestone,
|
| 230 |
|
| 231 |
except Exception as e:
|
| 232 |
return f"Error: {str(e)}", "Failure", "", "", "0%"
|
| 233 |
|
| 234 |
-
# Gradio UI
|
| 235 |
with gr.Blocks(css="""
|
| 236 |
.gradio-container {
|
| 237 |
background-color: #f0f4f8;
|
|
@@ -289,16 +284,15 @@ with gr.Blocks(css="""
|
|
| 289 |
project_name_input = gr.Textbox(label="Project Name (Required)", placeholder="e.g. Project_12345")
|
| 290 |
|
| 291 |
submit_button = gr.Button("Process Image")
|
| 292 |
-
output_html = gr.HTML(label="Result")
|
| 293 |
upload_status = gr.Textbox(label="Upload Status")
|
| 294 |
milestone = gr.Textbox(label="Detected Milestone")
|
| 295 |
-
confidence = gr.Textbox(label="Confidence Score") # Kept for compatibility, but unused
|
| 296 |
progress = gr.Textbox(label="Completion Percentage", interactive=False)
|
| 297 |
|
| 298 |
submit_button.click(
|
| 299 |
fn=process_image,
|
| 300 |
inputs=[image_input, project_name_input],
|
| 301 |
-
outputs=[output_html, upload_status, milestone,
|
| 302 |
)
|
| 303 |
|
| 304 |
-
demo.launch(share=True)
|
|
|
|
| 88 |
|
| 89 |
# Adjust milestone detection based on internal/external features
|
| 90 |
if milestone == "Walls Erected" and any("interior" in img_text.lower() for img_text in [os.path.basename(image)] if img_text):
|
|
|
|
| 91 |
if any(keyword in str(os.path.basename(image)).lower() for keyword in ["electrical", "plumbing", "wiring", "pipes"]):
|
| 92 |
+
milestone = "Completed"
|
| 93 |
else:
|
| 94 |
+
milestone = "Walls Erected"
|
| 95 |
|
| 96 |
milestones.append(milestone)
|
| 97 |
|
|
|
|
| 105 |
}
|
| 106 |
percent_complete = milestone_completion_map.get(final_milestone, 0)
|
| 107 |
|
|
|
|
| 108 |
completion_details = {
|
| 109 |
"Planning": {
|
| 110 |
"completed": [
|
|
|
|
| 164 |
completed_html = "".join([f'<li style="color: green;">✔ {task}</li>' for task in completed_tasks])
|
| 165 |
not_completed_html = "".join([f'<li style="color: red;">✘ {task}</li>' for task in not_completed_tasks])
|
| 166 |
|
|
|
|
| 167 |
result_html = f"""
|
| 168 |
<div style="font-family: Arial, sans-serif; padding: 20px; background-color: #f9f9f9; border-radius: 10px;">
|
| 169 |
<h2 style="color: #2c3e50; text-align: center;">Project Summary</h2>
|
|
|
|
| 203 |
</div>
|
| 204 |
"""
|
| 205 |
|
|
|
|
| 206 |
now = datetime.now(local_timezone)
|
| 207 |
local_time = now.strftime("%Y-%m-%dT%H:%M:%S") + now.strftime("%z")[:-2] + ":" + now.strftime("%z")[-2:]
|
| 208 |
|
|
|
|
| 209 |
record = {
|
| 210 |
"Name__c": project_name,
|
| 211 |
"Current_Milestone__c": final_milestone,
|
|
|
|
| 221 |
except Exception as e:
|
| 222 |
return f"Error: Failed to update Salesforce - {str(e)}", "Failure", "", "", 0
|
| 223 |
|
| 224 |
+
return result_html, "Success", final_milestone, f"{percent_complete}%"
|
| 225 |
|
| 226 |
except Exception as e:
|
| 227 |
return f"Error: {str(e)}", "Failure", "", "", "0%"
|
| 228 |
|
| 229 |
+
# Gradio UI
|
| 230 |
with gr.Blocks(css="""
|
| 231 |
.gradio-container {
|
| 232 |
background-color: #f0f4f8;
|
|
|
|
| 284 |
project_name_input = gr.Textbox(label="Project Name (Required)", placeholder="e.g. Project_12345")
|
| 285 |
|
| 286 |
submit_button = gr.Button("Process Image")
|
| 287 |
+
output_html = gr.HTML(label="Result")
|
| 288 |
upload_status = gr.Textbox(label="Upload Status")
|
| 289 |
milestone = gr.Textbox(label="Detected Milestone")
|
|
|
|
| 290 |
progress = gr.Textbox(label="Completion Percentage", interactive=False)
|
| 291 |
|
| 292 |
submit_button.click(
|
| 293 |
fn=process_image,
|
| 294 |
inputs=[image_input, project_name_input],
|
| 295 |
+
outputs=[output_html, upload_status, milestone, progress]
|
| 296 |
)
|
| 297 |
|
| 298 |
+
demo.launch(share=True)
|