Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -226,15 +226,30 @@ def detect_document(text):
|
|
| 226 |
# VEHICLE PLATE NUMBER
|
| 227 |
# =========================
|
| 228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
plate_match = re.search(
|
| 230 |
-
|
| 231 |
text.upper()
|
| 232 |
)
|
| 233 |
|
| 234 |
if plate_match:
|
|
|
|
| 235 |
return {
|
| 236 |
"document_type": "vehicle_plate",
|
| 237 |
-
"confidence":
|
| 238 |
"matched_keywords": [plate_match.group()]
|
| 239 |
}
|
| 240 |
|
|
|
|
| 226 |
# VEHICLE PLATE NUMBER
|
| 227 |
# =========================
|
| 228 |
|
| 229 |
+
plate_patterns = [
|
| 230 |
+
|
| 231 |
+
# Standard Nigerian plates
|
| 232 |
+
r"[A-Z]{2,3}\s?\d{2,3}[A-Z]{1,2}",
|
| 233 |
+
|
| 234 |
+
# OCR damaged versions
|
| 235 |
+
r"[A-Z]{1,3}\d{2,3}[A-Z]{1,3}",
|
| 236 |
+
|
| 237 |
+
# Hyphen formats
|
| 238 |
+
r"[A-Z]{2,3}-?\d{2,3}-?[A-Z]{1,2}"
|
| 239 |
+
]
|
| 240 |
+
|
| 241 |
+
for pattern in plate_patterns:
|
| 242 |
+
|
| 243 |
plate_match = re.search(
|
| 244 |
+
pattern,
|
| 245 |
text.upper()
|
| 246 |
)
|
| 247 |
|
| 248 |
if plate_match:
|
| 249 |
+
|
| 250 |
return {
|
| 251 |
"document_type": "vehicle_plate",
|
| 252 |
+
"confidence": 85,
|
| 253 |
"matched_keywords": [plate_match.group()]
|
| 254 |
}
|
| 255 |
|