Upload 2 files
Browse files- ocr_response.py +7 -0
- source_classifier.py +3 -1
ocr_response.py
CHANGED
|
@@ -3,6 +3,7 @@ import time
|
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
|
| 5 |
from gadalka import confidence_from_score
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def get_warning(confidence):
|
|
@@ -149,6 +150,11 @@ def build_response(best, candidates, passes_used, started_at, image_debug):
|
|
| 149 |
ok = confidence != "none"
|
| 150 |
if image_debug.get("source") in {"full_frame", "image", "document"} and confidence != "high":
|
| 151 |
ok = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
elapsed_ms = round((time.perf_counter() - started_at) * 1000)
|
| 153 |
vehicle_type = best.get("vehicle_type", "unknown")
|
| 154 |
notice = vehicle_notice(vehicle_type)
|
|
@@ -173,6 +179,7 @@ def build_response(best, candidates, passes_used, started_at, image_debug):
|
|
| 173 |
"preprocess": best.get("preprocess", ""),
|
| 174 |
"raw_text": best.get("raw_text", ""),
|
| 175 |
"source_chunk": best.get("source_chunk", ""),
|
|
|
|
| 176 |
"reasons": best.get("reasons", []),
|
| 177 |
"candidates": [public_candidate(candidate) for candidate in candidates[:10]],
|
| 178 |
},
|
|
|
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
|
| 5 |
from gadalka import confidence_from_score
|
| 6 |
+
from source_classifier import candidate_has_heavy_repairs
|
| 7 |
|
| 8 |
|
| 9 |
def get_warning(confidence):
|
|
|
|
| 150 |
ok = confidence != "none"
|
| 151 |
if image_debug.get("source") in {"full_frame", "image", "document"} and confidence != "high":
|
| 152 |
ok = False
|
| 153 |
+
source_class = (image_debug.get("source_class") or {}).get("class")
|
| 154 |
+
candidate_risk = []
|
| 155 |
+
if source_class == "document" and candidate_has_heavy_repairs(best):
|
| 156 |
+
ok = False
|
| 157 |
+
candidate_risk.append("document_heavy_repair_not_confirmed")
|
| 158 |
elapsed_ms = round((time.perf_counter() - started_at) * 1000)
|
| 159 |
vehicle_type = best.get("vehicle_type", "unknown")
|
| 160 |
notice = vehicle_notice(vehicle_type)
|
|
|
|
| 179 |
"preprocess": best.get("preprocess", ""),
|
| 180 |
"raw_text": best.get("raw_text", ""),
|
| 181 |
"source_chunk": best.get("source_chunk", ""),
|
| 182 |
+
"candidate_risk": candidate_risk,
|
| 183 |
"reasons": best.get("reasons", []),
|
| 184 |
"candidates": [public_candidate(candidate) for candidate in candidates[:10]],
|
| 185 |
},
|
source_classifier.py
CHANGED
|
@@ -56,7 +56,9 @@ def classify_full_frame_source(pass_result, image_debug):
|
|
| 56 |
height = image_debug.get("ocr_height") or image_debug.get("original_height") or 0
|
| 57 |
aspect = width / max(height, 1)
|
| 58 |
|
| 59 |
-
if
|
|
|
|
|
|
|
| 60 |
source_class = "document"
|
| 61 |
elif plate_hits >= 1 or aspect >= 1.35:
|
| 62 |
source_class = "vin_plate"
|
|
|
|
| 56 |
height = image_debug.get("ocr_height") or image_debug.get("original_height") or 0
|
| 57 |
aspect = width / max(height, 1)
|
| 58 |
|
| 59 |
+
if plate_hits >= 1 and aspect >= 1.25:
|
| 60 |
+
source_class = "vin_plate"
|
| 61 |
+
elif document_hits >= 2 or context_count >= 3 or chunks_count >= 12:
|
| 62 |
source_class = "document"
|
| 63 |
elif plate_hits >= 1 or aspect >= 1.35:
|
| 64 |
source_class = "vin_plate"
|