Repository navigation
ocr: POST /ocr in PaddleX's contract (#2440 step 6) - #2575
Conversation
|
Thanks @laudney. An early read of the last step, so the fixes can ride the rebase:
Replacing the two source-copied messages with your own wording is done; thanks. This is the last step, after #2574.
|
|
Thanks @ashhart. Both points are done; the code change is a local commit that goes up with the rebase after #2574.
Choices for the three rows with no published source (my recommendation first):
While I tested point 1 with PDFium and libjpeg-turbo present, I found that #2571's PDF run test scripted its replies as
|
|
Thanks @laudney, and thanks for the source table, which made this quick to check. On point 1: the You asked us to choose on two points. We'll take (a) on both:
Thanks also for catching the #2571 PDF run test that only passed because it skipped without PDFium. Please include these in the rebase after #2574:
Once that's in and CI is green, it follows #2574 into the landing queue, and #2440 closes with it.
|
9d0bde2 to
5a57365
Compare
|
@ashhart rebased onto main
This is the last step of #2440. |
|
Thanks @laudney. The document page count now stays visible when processing is cut, with the tests and docs distinguishing it from the pages read. The source table, chosen error format and reading order, and repeated-query refusal are present too. This merges cleanly with current main and is ready for the normal final CI gate. No additional model or device run is requested for this API step.
|
PaddleX's replies carry a logId that is a UUID v4 when the client sends none, and the benchmark receipt already builds one for its run id. The builder moves to ids.zig as uuid4 beside the other id helpers, and runId calls it, so both callers share one source.
PaddleX's serving clients post JSON with a base64 file and read prunedResult and a visualisation, so POST /ocr now answers JSON bodies in PaddleX's envelope: fields converted as its pydantic models convert them, rec_* lines filtered by textRecScoreThresh, integer polygons rounded half to even, word boxes on request, and inputImage and ocrImage with each polygon outlined under the shared image budget. A PDF is read to the page budget as PaddleX reads its first max_num_input_imgs pages, with dataInfo.numPages still the document's page count so a client sees the cut; detector knobs it cannot apply are refused, and file URLs share the Mistral route's fetch.
The API guide adds PaddleX to the /ocr contract choice: JSON bodies, its 422 failures and envelope, PaddleX file URLs, the reading of a PDF to the page budget with a link to the PaddleX page that defines the cut, visualisations in the image budget and their libjpeg-turbo need, word boxes, and the PaddleX section with its fields, key order and dataInfo, whose numPages is the document's page count while pages lists the pages read; the changelog stays with the maintainer.
5a57365 to
98b0867
Compare
|
Thank you @laudney. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
file,fileType)POST /ocr:prunedResultpolygons, texts and boxes;ocrImage/inputImageStep 6 of the stack #2440 set out, and the last. It follows #2574, now on main.
paddlex_test.zig: the documented call for an image and a PDF, the envelope on every failure (logId,errorCode,errorMsg), lax field conversion, and each detector or preprocessing switch refusedProvenance, following your ruling on #2530: the field names and the reply shape follow PaddleX's published serving reference. Schema errors keep pydantic's documented error
typeand a dot-joinedloc;msgis the text pydantic's published docs print for six of those types (for example "Field required" on its types and unions pages), and our own text for the rest. "Invalid input file" and "Unsupported file type", which came from PaddleX's serving source, are replaced by our own messages.Sources: OCR = PaddleX OCR pipeline (release/3.7): its "API Reference" for
POST /ocr, its "2.2.1 Command Line Experience" example output and its "2.2.2 Python Script Integration" field list; PC = pydantic conversion table; PE = pydantic validation errors; FA = FastAPI handling errors.POST /ocr;file(URL or base64);fileType0 for a PDF, 1 for an image, inferred when absentuseDocOrientationClassify,useDocUnwarping,useTextlineOrientation,textDetLimitSideLen,textDetLimitType,textDetThresh,textDetBoxThresh,textDetUnclipRatio,textRecScoreThresh(default 0.0),returnWordBox,visualizetextDet*fields only as null"0.5"as a number,"yes"as a boolean)typenames, andmsgfor six of themmsgis our own text for the restlogId,errorCode,errorMsg: 0 and "Success" on success; on failureerrorCode"Same as the response status code" anderrorMsga stringerrorMsgfor a schema error: a string that holds the JSON list[{"type", "loc", "msg"}],locdot-joined (body.file)errorMsgas a string, and it stays one; the list inside it and the dot-joinedlocare oursocrResults: one entry a page read;ocrImage,docPreprocessingImage,inputImageas base64 JPEG or nullfilerow: "only the first 10 pages will be processed"; our cut is the page budget (TENSORFOLD_MAX_PDF_PAGES, default 16)dataInfo:{"width", "height", "type": "image"}, or{"numPages", "pages": [{"width", "height"}], "type": "pdf"}withnumPagesthe document's page countnumPagescounting the whole document lets a client see a cutprunedResultisreswithoutinput_pathandpage_indexmodel_settings{"use_doc_preprocessor": false, "use_textline_orientation": false}text_type"general"textline_orientation_angles-1 for each linedt_polys,rec_texts,rec_scores,rec_polys,rec_boxes([x_min, y_min, x_max, y_max]), in the example's key order;text_word,text_word_boxeswithreturnWordBoxrec_*keep the lines scored at or abovetextRecScoreThreshtext_rec_score_thresh"; ours also keeps a score equal to it, so at the default 0.0 every line staystext_det_params,doc_preprocessor_resanddt_scoresleft outdoc_preprocessor_res"exists only whenuse_doc_preprocessor=True"; the example has nodt_scores.text_det_paramsis left out because TensorFold has no detector whose settings it could reportdt_polys,rec_polysorrec_texts. Ours: the reader's block order, so a two-column page keeps its columnsWhat this changes
POST /ocrgains PaddleX's OCR serving contract, chosen for JSON (or noContent-Typewith a body starting{), or?format=paddlex:fileas base64, a data URL or an HTTPS URL,fileType0 (PDF) or 1 (image), or sniffed when absent. A PDF is read to its first pages up to the page budget, as PaddleX reads its firstmax_num_input_imgspages;dataInfo.numPagesis the document's page count, so a client sees the cut, andocrResultsanddataInfo.pageslist the pages read.visualize(default true) adds the page and the page with each polygon outlined, inside the request's image budget. The UUID helper moves toids.zigforlogId.9a38b1f7b, with ocr: POST /v1/ocr on dots.mocr for images (#2440 step 1) #2570 to ocr: POST /ocr in docTR's contract (#2440 step 5) #2574; 3 commitsatc overlap --jsonon this head: Nemotron 3.5 Transcribe: audio input, the 65,536-token window, an hour of audio, MTP drafts #1632 merges clean; lfm3: add native Metal vision support above the text decoder #1502 conflicts, but only in the file where it already conflicts with main, so this step adds none.Checks on this head
5a5736537, on main9a38b1f7b. Rebuilt like ocr: PDF documents and pages on /v1/ocr, one page at a time (#2440 step 2) #2571 to ocr: POST /ocr in docTR's contract (#2440 step 5) #2574: the step-6 change, with the review fixes (a repeated query name refused;numPagesthe document's page count, with its test and the PaddleX link indocs/api.md), applied to main in 3 commits with the original subjects. Each file's change equals the reviewed change, exceptzig/src/server/ids.zig, whereuuid4now sits aftermakebecause main grew the file's end, andCHANGELOG.md, which is no longer touched.python3 tools/zig/lean_check.py: 165 on main and 165 on this head, the same list, 0 new.zig build test-ocr-host test-api-boundaries test-server-cpu test-dots-mocr-host test-glm-ocr-host check-native-hip-host -Dhip=true: 24/24 steps, 2288 of 2306 pass, 18 skip, 0 failzig fmt --check zig/src build.zig zig/buildandgit diff --check: clean9a38b1f7bis clean.TF_DOTS_OCR_DIRruns and no PDFium on this run); thenumPagesPDF test ran with PDFium on the earlier head. CUDA, Metal and Windows: no OCR reader is offered there; the readers are wired into the HIP offers only.Receipt
fileType: 1: 200, 3 lines,ocrImageandinputImage900x260 JPEG, outlines onocrImageonly; PDFfileType: 0: 200,numPages2, both images 1224x1584;application/json; charset=utf-8: 200; a cut page: 422 witherrorCode422 andlogId.c517f4379.--vision;visualizeneeds libjpeg-turbo 3.1.4.1, as PDF input already does.9c9bf542c, checks on main9a38b1f7b; Zig 0.17.0; ROCm 10.1 (hipcc HIP 7.16); one Radeon AI PRO R9700 (gfx1201); Linux; dots.mocrdots-studio/dots.mocre539fbb52280393adc081b289ec597430a0f9031, GLM-OCRzai-org/GLM-OCR2e85a62840ccac27daa451df36c736c4636b8628; PDFium chromium/7725; libjpeg-turbo 3.1.4.1. The end-to-end client receipts ran on the whole stack's code (c517f4379, byte-equal to step 6's OCR files), which serves this step's requests through this step's code.Checklist