Spaces:
Sleeping
Sleeping
Yaz Hobooti
commited on
Commit
Β·
ad64d27
1
Parent(s):
5fa0489
Add barcode detection debugging and test script
Browse files- app.py +9 -1
- test_barcode.py +83 -0
app.py
CHANGED
|
@@ -54,9 +54,11 @@ except Exception:
|
|
| 54 |
try:
|
| 55 |
from barcode_reader import read_barcodes_from_path
|
| 56 |
HAS_BARCODE = True
|
| 57 |
-
|
|
|
|
| 58 |
read_barcodes_from_path = None
|
| 59 |
HAS_BARCODE = False
|
|
|
|
| 60 |
|
| 61 |
# -------------------- Core Data --------------------
|
| 62 |
@dataclass
|
|
@@ -1172,6 +1174,12 @@ def compare_pdfs(file_a, file_b):
|
|
| 1172 |
|
| 1173 |
# Debug: Print barcode detection results
|
| 1174 |
print(f"Barcode detection results - A: {len(bar_a)} codes, B: {len(bar_b)} codes")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1175 |
except Exception as e:
|
| 1176 |
print(f"Barcode detection error: {e}")
|
| 1177 |
bar_a, info_a = [], []
|
|
|
|
| 54 |
try:
|
| 55 |
from barcode_reader import read_barcodes_from_path
|
| 56 |
HAS_BARCODE = True
|
| 57 |
+
print("β Barcode reader imported successfully")
|
| 58 |
+
except Exception as e:
|
| 59 |
read_barcodes_from_path = None
|
| 60 |
HAS_BARCODE = False
|
| 61 |
+
print(f"β Barcode reader import failed: {e}")
|
| 62 |
|
| 63 |
# -------------------- Core Data --------------------
|
| 64 |
@dataclass
|
|
|
|
| 1174 |
|
| 1175 |
# Debug: Print barcode detection results
|
| 1176 |
print(f"Barcode detection results - A: {len(bar_a)} codes, B: {len(bar_b)} codes")
|
| 1177 |
+
print(f"Raw codes_a: {len(codes_a)} items")
|
| 1178 |
+
print(f"Raw codes_b: {len(codes_b)} items")
|
| 1179 |
+
if codes_a:
|
| 1180 |
+
print(f"Sample code_a: {codes_a[0] if codes_a else 'None'}")
|
| 1181 |
+
if codes_b:
|
| 1182 |
+
print(f"Sample code_b: {codes_b[0] if codes_b else 'None'}")
|
| 1183 |
except Exception as e:
|
| 1184 |
print(f"Barcode detection error: {e}")
|
| 1185 |
bar_a, info_a = [], []
|
test_barcode.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Simple test script to verify barcode reader functionality
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
def test_barcode_imports():
|
| 7 |
+
"""Test if all required modules can be imported"""
|
| 8 |
+
print("Testing barcode reader imports...")
|
| 9 |
+
|
| 10 |
+
try:
|
| 11 |
+
import numpy as np
|
| 12 |
+
print("β numpy imported")
|
| 13 |
+
except Exception as e:
|
| 14 |
+
print(f"β numpy failed: {e}")
|
| 15 |
+
return False
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
from PIL import Image
|
| 19 |
+
print("β PIL imported")
|
| 20 |
+
except Exception as e:
|
| 21 |
+
print(f"β PIL failed: {e}")
|
| 22 |
+
return False
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
import cv2
|
| 26 |
+
print("β OpenCV imported")
|
| 27 |
+
has_barcode = hasattr(cv2, 'barcode') and hasattr(getattr(cv2, 'barcode'), 'BarcodeDetector')
|
| 28 |
+
print(f"β OpenCV barcode detector: {has_barcode}")
|
| 29 |
+
except Exception as e:
|
| 30 |
+
print(f"β OpenCV failed: {e}")
|
| 31 |
+
return False
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
import zxingcpp
|
| 35 |
+
print("β zxingcpp imported")
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print(f"β zxingcpp failed: {e}")
|
| 38 |
+
return False
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
import fitz
|
| 42 |
+
print("β PyMuPDF imported")
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print(f"β PyMuPDF failed: {e}")
|
| 45 |
+
return False
|
| 46 |
+
|
| 47 |
+
try:
|
| 48 |
+
from barcode_reader import read_barcodes_from_path
|
| 49 |
+
print("β barcode_reader imported")
|
| 50 |
+
return True
|
| 51 |
+
except Exception as e:
|
| 52 |
+
print(f"β barcode_reader failed: {e}")
|
| 53 |
+
return False
|
| 54 |
+
|
| 55 |
+
def test_barcode_function():
|
| 56 |
+
"""Test the barcode reader function with a simple case"""
|
| 57 |
+
print("\nTesting barcode reader function...")
|
| 58 |
+
|
| 59 |
+
try:
|
| 60 |
+
from barcode_reader import read_barcodes_from_path
|
| 61 |
+
print("β read_barcodes_from_path function available")
|
| 62 |
+
|
| 63 |
+
# Test with a non-existent file (should return empty list, not crash)
|
| 64 |
+
result = read_barcodes_from_path("nonexistent.pdf")
|
| 65 |
+
print(f"β Function handles non-existent file: {type(result)}")
|
| 66 |
+
|
| 67 |
+
return True
|
| 68 |
+
except Exception as e:
|
| 69 |
+
print(f"β barcode function test failed: {e}")
|
| 70 |
+
return False
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
print("=== Barcode Reader Test ===")
|
| 74 |
+
|
| 75 |
+
imports_ok = test_barcode_imports()
|
| 76 |
+
if imports_ok:
|
| 77 |
+
function_ok = test_barcode_function()
|
| 78 |
+
if function_ok:
|
| 79 |
+
print("\nβ All tests passed!")
|
| 80 |
+
else:
|
| 81 |
+
print("\nβ Function test failed")
|
| 82 |
+
else:
|
| 83 |
+
print("\nβ Import tests failed")
|