harsh-dev commited on
Commit
6bf854f
·
unverified ·
1 Parent(s): 3ba5b62
Files changed (1) hide show
  1. diff_ai.py +16 -2
diff_ai.py CHANGED
@@ -29,6 +29,11 @@ All models are lazy-loaded (thread-safely). Falls back to classical pipeline
29
  (diff.py) if any required model is unavailable — see app.py for the wiring.
30
  """
31
  import threading
 
 
 
 
 
32
 
33
  import cv2
34
  import numpy as np
@@ -453,7 +458,7 @@ def _composite_object(base, object_img, mask, bbox, color):
453
  # MAIN ENTRY
454
  # =====================================================================
455
 
456
- def compare_images_ai(img1_path, img2_path, output_path, heatmap_path):
457
  """End-to-end change-region-driven AI pipeline. Raises RuntimeError
458
  if any required model is unavailable."""
459
  if not _get_loftr() or not _get_sam() or not _get_dinov2():
@@ -637,4 +642,13 @@ def compare_images_ai(img1_path, img2_path, output_path, heatmap_path):
637
  "object_changes": n_total,
638
  "severity": severity,
639
  "alignment_failed": alignment_failed,
640
- }
 
 
 
 
 
 
 
 
 
 
29
  (diff.py) if any required model is unavailable — see app.py for the wiring.
30
  """
31
  import threading
32
+ try:
33
+ import spaces
34
+ HAS_SPACES = True
35
+ except ImportError:
36
+ HAS_SPACES = False
37
 
38
  import cv2
39
  import numpy as np
 
458
  # MAIN ENTRY
459
  # =====================================================================
460
 
461
+ def _compare_images_ai_impl(img1_path, img2_path, output_path, heatmap_path):
462
  """End-to-end change-region-driven AI pipeline. Raises RuntimeError
463
  if any required model is unavailable."""
464
  if not _get_loftr() or not _get_sam() or not _get_dinov2():
 
642
  "object_changes": n_total,
643
  "severity": severity,
644
  "alignment_failed": alignment_failed,
645
+ }
646
+
647
+
648
+ if HAS_SPACES:
649
+ @spaces.GPU
650
+ def compare_images_ai(img1_path, img2_path, output_path, heatmap_path):
651
+ return _compare_images_ai_impl(img1_path, img2_path, output_path, heatmap_path)
652
+ else:
653
+ def compare_images_ai(img1_path, img2_path, output_path, heatmap_path):
654
+ return _compare_images_ai_impl(img1_path, img2_path, output_path, heatmap_path)