Rekham1110 commited on
Commit
a46f1d8
·
verified ·
1 Parent(s): afe6823

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -64,7 +64,7 @@ def analyze_image_with_hf(image_path):
64
 
65
  return detected_elements
66
 
67
- # Image processing and Salesforce upload with image preview
68
  def process_image(images, project_name):
69
  try:
70
  if not images or len(images) == 0:
@@ -213,7 +213,7 @@ def process_image(images, project_name):
213
  {completed_html}
214
  </ul>
215
  </details>
216
- <p style="color: green;">Project is fully completed as of 02:22 PM IST, June 20, 2025.</p>
217
  </div>
218
  """
219
  else:
@@ -251,7 +251,7 @@ def process_image(images, project_name):
251
  {not_completed_html}
252
  </ul>
253
  </details>
254
- <p style="color: orange;">Construction is in progress at {final_milestone} stage as of 02:22 PM IST, June 20, 2025.</p>
255
  </div>
256
  """
257
 
@@ -262,8 +262,8 @@ def process_image(images, project_name):
262
 
263
  combined_html = "<div>" + "".join(results_html) + "</div>"
264
 
265
- # Set current time to 02:22 PM IST, June 20, 2025
266
- now = local_timezone.localize(datetime(2025, 6, 20, 14, 22))
267
  local_time = now.strftime("%Y-%m-%dT%H:%M:%S") + now.strftime("%z")[:-2] + ":" + now.strftime("%z")[-2:]
268
 
269
  record = {
@@ -282,12 +282,12 @@ def process_image(images, project_name):
282
  except Exception as e:
283
  return f"Error: Failed to update Salesforce - {str(e)}", None, "Failure", "", "", 0
284
 
285
- return combined_html, Image.open(saved_image_path) if images else None, ",".join(upload_statuses), ",".join(milestones), "", ",".join(progresses)
286
 
287
  except Exception as e:
288
  return f"Error: {str(e)}", None, "Failure", "", "", "0%"
289
 
290
- # Gradio UI with enhanced styling and image preview
291
  with gr.Blocks(css="""
292
  .gradio-container {
293
  background-color: #f0f4f8;
@@ -342,20 +342,26 @@ with gr.Blocks(css="""
342
  gr.Markdown("<h1 class='title'>Construction Progress Analyzer</h1>")
343
  with gr.Row():
344
  image_input = gr.Files(type="filepath", label="Upload Construction Site Photos (JPG/PNG, ≤ 20MB)")
 
345
  project_name_input = gr.Textbox(label="Project Name (Required)", placeholder="e.g. Project_12345")
346
 
347
  submit_button = gr.Button("Process Image")
348
  output_html = gr.HTML(label="Result")
349
- output_image = gr.Image(label="Uploaded Image Preview") # Added image preview component
350
  upload_status = gr.Textbox(label="Upload Status")
351
  milestone = gr.Textbox(label="Detected Milestone")
352
  confidence = gr.Textbox(label="Confidence Score") # Kept for compatibility, but unused
353
  progress = gr.Textbox(label="Completion Percentage", interactive=False)
354
 
 
 
 
 
 
 
355
  submit_button.click(
356
  fn=process_image,
357
  inputs=[image_input, project_name_input],
358
- outputs=[output_html, output_image, upload_status, milestone, confidence, progress]
359
  )
360
 
361
  demo.launch(share=True)
 
64
 
65
  return detected_elements
66
 
67
+ # Image processing and Salesforce upload with live preview
68
  def process_image(images, project_name):
69
  try:
70
  if not images or len(images) == 0:
 
213
  {completed_html}
214
  </ul>
215
  </details>
216
+ <p style="color: green;">Project is fully completed as of 02:26 PM IST, June 20, 2025.</p>
217
  </div>
218
  """
219
  else:
 
251
  {not_completed_html}
252
  </ul>
253
  </details>
254
+ <p style="color: orange;">Construction is in progress at {final_milestone} stage as of 02:26 PM IST, June 20, 2025.</p>
255
  </div>
256
  """
257
 
 
262
 
263
  combined_html = "<div>" + "".join(results_html) + "</div>"
264
 
265
+ # Set current time to 02:26 PM IST, June 20, 2025
266
+ now = local_timezone.localize(datetime(2025, 6, 20, 14, 26))
267
  local_time = now.strftime("%Y-%m-%dT%H:%M:%S") + now.strftime("%z")[:-2] + ":" + now.strftime("%z")[-2:]
268
 
269
  record = {
 
282
  except Exception as e:
283
  return f"Error: Failed to update Salesforce - {str(e)}", None, "Failure", "", "", 0
284
 
285
+ return combined_html, Image.open(images[0]) if images else None, ",".join(upload_statuses), ",".join(milestones), "", ",".join(progresses)
286
 
287
  except Exception as e:
288
  return f"Error: {str(e)}", None, "Failure", "", "", "0%"
289
 
290
+ # Gradio UI with enhanced styling and live image preview
291
  with gr.Blocks(css="""
292
  .gradio-container {
293
  background-color: #f0f4f8;
 
342
  gr.Markdown("<h1 class='title'>Construction Progress Analyzer</h1>")
343
  with gr.Row():
344
  image_input = gr.Files(type="filepath", label="Upload Construction Site Photos (JPG/PNG, ≤ 20MB)")
345
+ image_preview = gr.Image(label="Image Preview", interactive=False) # Live preview here
346
  project_name_input = gr.Textbox(label="Project Name (Required)", placeholder="e.g. Project_12345")
347
 
348
  submit_button = gr.Button("Process Image")
349
  output_html = gr.HTML(label="Result")
 
350
  upload_status = gr.Textbox(label="Upload Status")
351
  milestone = gr.Textbox(label="Detected Milestone")
352
  confidence = gr.Textbox(label="Confidence Score") # Kept for compatibility, but unused
353
  progress = gr.Textbox(label="Completion Percentage", interactive=False)
354
 
355
+ # Update preview on file upload
356
+ image_input.change(
357
+ fn=lambda x: Image.open(x[0]) if x else None,
358
+ inputs=[image_input],
359
+ outputs=[image_preview]
360
+ )
361
  submit_button.click(
362
  fn=process_image,
363
  inputs=[image_input, project_name_input],
364
+ outputs=[output_html, image_preview, upload_status, milestone, confidence, progress]
365
  )
366
 
367
  demo.launch(share=True)