Changed AI to new version

This commit is contained in:
SepehrYahyaee
2026-11-03 15:58:23 +03:30
parent c5aa0f925e
commit e75a144e50
11 changed files with 4349 additions and 61 deletions
+10 -6
View File
@@ -8,7 +8,7 @@ Set these **API environment variables** and restart the API:
```dotenv
AI_DAMAGE_ENABLED=true
AI_DAMAGE_URL=http://79.132.207.77:30527
AI_DAMAGE_URL=http://79.132.207.77:30531
AI_DAMAGE_TIMEOUT_MS=180000
```
@@ -30,23 +30,25 @@ No existing claim documents are migrated or rewritten. The old login/profile/dow
- Enqueueing waits only for a Mongo upsert, never for inference; a persistence error is logged without failing upload. Viewing the tab re-schedules a missed current photo.
- One worker per instance polls every five seconds and claims one job atomically. A lease token guards completion writes across replicas. Expired leases recover after restart; leases last the configured HTTP timeout plus 60 seconds. Storage must be shared across replicas.
- Each claim/photo has one job. Repeated reads/uploads do not reset successful or failed analysis. Transient network/server/invalid-response failures retry up to three claims, with 30/60-second delays. Terminal 4xx image errors require explicit retry. A retry exhausted by process crashes is also marked failed.
- The worker sends one multipart `images` file to `/pipeline/detect_parts_with_damages`, with `side`, `segments`, `bounding_box`, `severity`, `confidence` all `true`. Managed local files only; no URL fetching, redirects or arbitrary file paths. Maximum file size 20 MiB and response size 2 MiB.
- The worker sends one multipart `images` file to `POST /api/v1/assessments`, without the retired pipeline query flags. The provider also accepts batches of up to 12 images; this adapter intentionally keeps one photo per durable job, using the supported single-image request so results and retries stay tied to their source capture. Managed local files only; no URL fetching, redirects or arbitrary file paths. Maximum file size 15 MiB (enforced before upload), multipart body 16 MiB and response size 2 MiB.
- The provider's OpenAPI describes JPEG inputs. Current camera/compression flows emit JPEG; a rejected older format stays visible with a recoverable analysis error.
- Current media determines the displayed photos. Replaced and removed photos' job results are retained separately, but never attached to a newer photo or inserted into the live carousel. Existing parts revision history is untouched.
## JSON and coordinates
The verified provider OpenAPI declares top-level `distinct_damaged_parts_report` (`parts`, `report`), `damaged_part_table`, and `case_report`. Each part includes `part_name` and optional nullable `damage_severity`, `part_bbox`, `confidence`, `side`, `car_side`.
The assessment response contains `request_id`, pipeline provenance, vehicle color/body type, `damaged_parts`, `internal_damages`, and `case_report`. Each damaged part has `part`, `side`, `severity`, `damage_types`, `descriptions`, `localized`, and image-specific `evidence`. Bounding boxes now come from `evidence[].part.box`; confidence and instance IDs also come from the evidence part.
The adapter validates this envelope, bounds response/detection sizes and stores a compact result: `parts[{name,severity,bbox,confidence,side,carSide}]`, `report`, `caseReport`. The duplicated `damaged_part_table` is unnecessary for rendering and is not stored. Repeated part names remain separate detections. Missing/invalid boxes or confidence do not produce guessed values. Invalid envelopes are failures, not successful empty analyses.
The adapter retains one normalized part per damaged-part entry with all evidence for the uploaded photo (`image_index: 0`). Only localized parts with `link_status: linked` can produce overlays. Each part can have multiple evidence boxes; all share its numbered label in the UI. Missing/unlinked/invalid coordinates never produce guessed boxes. Evidence belonging to a different image index is excluded. Part descriptions, damage types, possible internal damages, vehicle details, request ID and pipeline versions/hashes are retained. Existing saved results from the retired pipeline remain readable, and the response normalizer retains legacy envelope compatibility.
Both HTTP error responses and HTTP-success responses containing `{error: {code, message, request_id}}` are failures. HTTP status controls automatic retries; unknown failures use the existing bounded retry policy. Code and request ID are saved for troubleshooting, while experts see Persian error feedback and the request ID. A generic HTTP 400 is no longer assumed to mean no car was found.
The drawing contract is **pixel coordinates in the uploaded image's displayed intrinsic orientation/dimensions**: `x1,y1,x2,y2`, origin top-left. The UI uses the original image's natural dimensions as the SVG viewBox, scales image and boxes together without letterboxing, and clips boxes to the image. If the provider instead emits resized-image coordinates or uses a different EXIF orientation, its contract must provide those dimensions/orientation before conversion; the UI does not infer them from the largest detection. Validate alignment using a known annotated photo supplied by the AI team before rollout.
No segmentation polygon is fabricated from a bounding box. The provider's current response has no usable mask/polygon field, despite `segments=true`.
Valid evidence polygons are retained, with invalid placeholder points such as `[null, null]` discarded. The current UI draws bounding boxes; it does not fabricate polygons or masks.
## Expert UI and access
Open **گزارش خسارت → تحلیل هوش مصنوعی**. Select a photo, inspect numbered boxes, toggle overlays or select a detected part to highlight its box. Severity, confidence and side are shown next to the detection; Persian image summary and full report are available below. Unknown provider labels remain readable rather than being mapped to a guessed catalog ID.
Open **گزارش خسارت → تحلیل هوش مصنوعی**. Select a photo, inspect numbered boxes, toggle overlays or select a detected part to highlight its box. Severity, confidence, side, damage types and descriptions are shown next to the detection. Vehicle color/body type and possible internal damage with likelihood/reasons are shown when available; the full report remains available below. Unknown provider labels remain readable rather than being mapped to a guessed catalog ID.
Pending images poll every five seconds while the tab is mounted and inference is enabled. Failed images offer **تحلیل دوباره تصاویر ناموفق**. Empty, disabled, image-load failure, fetch failure and retry failure states have separate feedback. Existing successful results remain visible when inference is disabled.
@@ -70,6 +72,8 @@ Expert endpoints reuse the exact existing claim-detail gate (role, organization,
## Implementation verification
The historical live probe below used the retired pipeline. The assessment API migration is covered by mocked response, multipart transport, error-envelope and image-size checks; it has not been verified against the live new provider.
On 2026-10-03 the real multipart adapter successfully called the development pipeline with [Front bumper broken.jpg](https://commons.wikimedia.org/wiki/File:Front_bumper_broken.jpg), a public photograph by Tiia Monto (CC BY-SA 3.0). It returned HTTP 200 and six detections, with Persian reports, severity, confidence and bounding boxes. Rendering was checked against the source JPEG's actual 2121×1188 dimensions. No customer photo was used for this probe. A separate synthetic blank JPEG returned HTTP 500; that failure is handled by the existing bounded retry/error path.
Backend checks cover upload-to-queue integration, immutable per-photo association, atomic job leases/recovery, retry limits, real multipart bytes/options, response validation, and expert/insurer/admin file-access gates. Frontend checks cover clipping/scaling, readable 24px number badges, report toggles, pending polling, retry, disabled cached results, empty images, fetch recovery and desktop/mobile overflow.